I would like to read the price volume data of Amibroker stock symbols using python. I cannot find anything useful on google for doing this. Anyone can help?
Cool:
Just do not hesistate to fully open the box of delicious candies
AmiBroker, as other trading frameworks do either, can provide data, but it is a compact ( ~ 3.5 MB .EXE
+ .DLL
s), performance optimised executable that does not, unlike Java or .NET programs, require any internal VM to interpret the user-processes on a byte-code level, but runs on a full steam on machine-code level.
While AB provides several integration options for Data-access, my advice -- after spending about last 12 years in quantitative R&D -- would be: go distributed ( forget to spend your time to implement just a particular access to some data-element ( Volume ) and do not further rely on state-sharing -- rather start using intelligent inter-process communications & smart inter-agent signalling python
-asks, AmiBroker
-replies ad-hoc etc. ).
Python side -- for free ( . . . be it run on the localhost
or another continent )
This is known to be pretty simple and sooooo flexible as per both extending and tools/modules availability, that lets me straight skip it here, you know better a priori what you need on python side and most of the needs have been implemented already or is quite simply added as a few module extensions.
AmiBroker side -- the harder part
Tomasz Janeczko wrote a lot on a particular mode of AB integration - the DLL
-based one. Why? DLL-s allow one the smooth and fully controllable integration one needs in a system-to-system communication architecture.
(cit.:) "... translate ... to C/C++ language and compile as
AFL
pluginDLL
. Doing so requires some C/C++ programming knowledge, a C/C++ compiler (free Visual Studio Express or GNU tools can be used) and AmiBroker Development Kit (ADK).
ADK contains instructions how to write your ownAFL
plugin along with code samples that are ready-to-compile. Some C/C++ knowledge is required though.
ADK is freely downloadable from
http://www.amibroker.com/bin/ADK.exe (self-extracing exe) or http://www.amibroker.com/bin/ADK.zip (zip archive)
NOTE: ADK is not for the beginners. It is for programmers (i.e. for people who already wrote some C/C++ code in their life)."
Be careful:
When plug-in
DLL
is written with AmiBroker Development Kit (ADK) it is usually compiled with Microsoft C runtime library. The “problem” is that depending on compiler used, different versions of C runtime are required for theDLL
to be loaded by the operating system.
For example Visual C++ 6.0 links againstMSVCRT.DLL
that is commonly found in all Windows starting from Windows XP so you can “forget” about installing the runtime. But when plugin is compiled with more recent Visual C++ 2005, 2008 or 2010 then required C runtime library is almost never present on target ( client ) computer.
In order to load the plugin compiled with VC2005 or higher, one must install proper run-time library on the client computer. The runtime must exactly match the compiler version and eventual compiler service pack used to compile theDLL
, otherwise operating system will not load theDLL
. Appropriate runtimes (vcredist.exe
) are in:VCInstallDir\SDK\v2.0\Bootstrapper\Packgages\vcredist_x86
orVCInstallDir\SDK\v2.0\Bootstrapper\Packgages\vcredist_x64
or similar directory (depending on VC version being used). Then suchvcredist.exe
must be shipped with the DLL to all clients for their installation.
Alternatively can compileDLL
with a static runtime library.
There is a freeware tool called Dependency Walker (http://www.dependencywalker.com/) that allows to check what givenDLL
needs to be loaded by the operating system.
Plus -- you absolutely need to make sure that your plugins use “Multithreaded DLL” run-time library. Godd news is, Visual C++ compilers (2005 and 2010) do not allow to choose single-threaded runtime anymore.
So -- put your DLL
into “Plugins” directory and if it does not show up in the data source list it means that its bitness ( 32bit / 64bit ) is not matching the AmiBroker one.
Having DLL
-mode ready to be used, one can implement a DLL
-based wrapper for almost any smart-messaging framework alike ZeroMQ
, nanomsg
et al and having achieved this, your imagination is the only limit in further system-to-system communications with python
.
python
-asks,AmiBroker
-repliesAmiBroker
-asks,python
-repliesAmiBroker
-asks,remote-GPU
-repliesAmiBroker
-asks,remote-AI/ML
-predicts and publishes targets for trade-setup / trade-mangement ( works with low latency times -- tens of[ms]
-- suitable for even low-intensity HFT strategies ),AmiBroker
-publishes,remote-ComputingGrid
-processes and signals to whoever else for any post-processing
I'm not sure what your scenario is, but you have a few options.
Ultimately, all the information stored about a stock is on the AB database, which you can access from your AFL. So, to get the value into Python, you can create a text file, that your Python code can read.
Your next option is to interact directly with the AB COM object, see the guide. I don't know how that can be done in Python.
Here's the COM object guide, under Quotation:
Quotation class represents one bar of price data
https://www.amibroker.com/guide/objects.html
The link below is an idea from another answer I've posted regarding AB COM interop.
Equivalent code of CreateObject in C#
Sethmo
You can try change this javascript which I modify Amibroker example to Python. This javascript will dump the Amibroker database to a file. This script will you some idea how the database in Amibroker can be accessed.
function FormatFloat( number )
{
number = 0.001 * Math.round( number * 1000 );
str = number.toString();
return str.substring( 0, str.indexOf(".") + 4 );
}
var oAB = new ActiveXObject("Broker.Application");
var fso = new ActiveXObject("Scripting.FileSystemObject");
/* Indicate the location and file name for the database dump. */
file = fso.OpenTextFile( "C:\\Info.txt", 2, true );
/* Indicate the location and name of the database to dump. */
oAB.LoadDatabase("C:\\Program Files (x86)\\AmiBroker\\Data");
var oStocks = oAB.Stocks;
var Qty = oStocks.Count;
for( i = 0; i < Qty; i++ ) { /* Loop through all the stocks in the database. */
oStock = oStocks(i);
for (j = 0; j < oStocks(i).Quotations.Count; j++) { /* Loop through all the ohlcv in each stock. */
oQuote = oStock.Quotations( j );
var oDate = new Date( oQuote.Date );
file.WriteLine( oStocks(i).Ticker + "," +
(oDate.getMonth()+1) + "/" + oDate.getDate() + "/" + oDate.getFullYear() + "," +
FormatFloat( oQuote.Open ) + "," +
FormatFloat( oQuote.High ) + "," +
FormatFloat( oQuote.Low ) + "," +
FormatFloat( oQuote.Close ) + "," +
Math.round( oQuote.Volume ) );
}
}
file.Close();
WScript.Echo("Export finished" );
//Price Volume of the ticker (Formula: Close x Volume)
Price_Volume = C*V
//Price Volume of specific ticker (eg. SPY) (Formula: Close x Volume)
Price_Volume_SPY = foreign("SPY","C")*foreign("SPY","V")
//Yesterday Price Volume of specific ticker (eg. SPY) (Formula: Close x Volume)
Yesterday_Price_Volume_SPY = Ref(foreign("SPY","C"),-1)*Ref(foreign("SPY","V"),-1)
© 2022 - 2024 — McMap. All rights reserved.