Hello , I want to know that is it possible to run Python Code on Amibroker?
Due to some reason,I want use NUMPY , Pandas(Python Module) on amibroker.
If can , how can I get resource? Maybe some code examples ?
Hello , I want to know that is it possible to run Python Code on Amibroker?
@Parsons Amibroker has an internal programming language called Amibroker Formula Language (AFL). it has some similarities to Numpy. Both are vectorized. However, AFL is specifically designed for trading system development. You can use Python externally with Amibroker in a couple ways. First, you could use Python to automate some Amibroker operations using OLE Automation. Secondly, through the file system, you can export data from Amibroker and do some external processing in Python. You could also integrate Python with Amibroker in the other direction. Amibroker can run external programs with the “batch” functionality and Amibroker can import time series data created by your Python script.
Here is example of integration AmiBroker with Python 2.7
and second example:
Python is much more elastic than AFL, so you can do pretty everything by combining both.
Wth all due to respect but that is nonsense. You can do pretty much “everything” with AFL alone.
And IMHO Python is a PITA to work with. If I’m comparing it to easiness of AFL then it is just “No, thank you”. But latter two sentences are just my opinion.
(BTW that marketcalls guy is just a copy&paste artist but not an expert on anything (AmiBroker related at least). Lots of sciolism. The one and only actual AmiBroker expertise can be found at amibroker.com and here at forum.amibroker.com ).
As I see it (based on experience) AFL is not designed for anything specifically. It is a very powerful language designed for anything imaginable and it is very easy to work with getting things done pretty quickly (even after years of usage it still amazes me). Trading system development is just a fraction of AFL/AmiBroker universe.
Everybody is using what better suits him/her. Thanks for your point of view
I see a lot of interest in academic circles and people with intellectual curiosity to learn Phyton and machine/deep learning for designing trading systems. This is getting more and more attention every day.
Though for strategies I am interested in, i.e momentum, mean reversion, pairs trading etc… I could only see none to limited benefit in terms of designing trading strategies with Phyton.
Therefore, with this limited scope I fail to grasp a pressing need to learn Phyton and think that I am much better of with AFL and Amibroker.
Simplicity is the ultimate sofistication.
I am convinced that I have what I need here with Amibroker to generate profitable returns for my strategies.
An exaggerated claim for sure. AFL works perfectly as a support for trading strategy development, but the scope of general-purpose programming is far beyond. Unicuique suum, to each his own
You’re mistaken. It shows that you have no academic background in computer science. It takes very very little for the machine to be able to execute ANY imaginable algorithm. Turing Machine is excellent example. One could argue that assembler or C/C++ is more powerful due talking directly to hardware but Python ??? Python was originally a toy language for people without programming expertise. It got popularity not because it was any good but because it does look “easy”. Even it’s syntax (no semicolons for statement end) shows its similarity to BASIC which was mediocre language for amateurs. If you want powerful AND FAST language use C/C++.
More importantly Python has serious problems with multithreading due to use of global interpreter lock https://wiki.python.org/moin/GlobalInterpreterLock
This alone is big show stopper.
In AmiBroker multithreading is hassle-free. Each AFL formula just works in parallel in separate threads without worries
Disclaimer: the above opinions are mine and your is likely to be different. All discussions about languages always lead to nowhere.
You can’t build cars and you can’t bake bread with AFL…
But you can calculate and output anything you want with it.
So far I haven’t really found any boundary preventing me from doing upper things.
Enlighten us all about what you can’t calculate/output/plot with it. I’m eager to get enlightened.
BTW here is just a fraction of some examples (mostly plots/tables)
Another info, people often (falsely) think that you are bound to selected symbol’s data.
No, you are not. You can do calculations and output results (via plot or analysis window etc.) on data being completely independent from selected “symbol” (symbol’s data can be any non price data too besides of that) and that data can exceed the number of elements of symbol’s data. So again no limits (other than hardware ones).
PS: And here below is another cute example (of calculations on data having nothing to do with selected symbol’s data).
Just recently I have replicated MS Exel’s pivot table feature.
What have I used for that? Easy. AFL!
Can you replicate it? If you can’t then rather listen to people having little bit more inside knowledge of what’s actually doable and what it is not.
I’m repeating: trading system development is just a fraction of what you can do in AmiBroker.
AFL is a very versatile language and AmiBroker is a very versatile tool (note: you also get a C/C++ API). You can code and calculate and output anything you want. Period.
Here is the sample data being used:
SalesPerson, Order Amount, Month Kathy, 925, January Kathy, 875, February Kathy, 500, February Kathy, 350, March James, 400, January James, 850, January James, 1500, January James, 400, March John, 235, February John, 850, January John, 600, March John, 250, January Jim, 400, February
I can back up said things. Some of you guys can’t so far.
Just try some similar examples in Amibroker and Quantopian.
I did some tests and found that Amibroker was >100 times faster even
while Quantopian announced a big improvement in their performance.
It would be nice to have a little 64 bit machinelearning in Amibroker.
But the optimizers work very fast in Amibroker.
Thanks for posting your crafty examples! I am especially interested in the series that exchanges data and charts directly with Excel. Would you be willing to share how you do that?
That’s true. Amibroker is far more faster than other testing tools. Once I was compering AmiBroker vs MultiChart and run an optimization process in two dimension backtest with 1281 iterations. The result time:
- AmiBroker : 1 minute, 26 seconds
- MultiCharts : 11 minutes, 2 seconds
So the speed is circa 7 times better in AmiBroker.
Python is of course much slower than MultiCharts and AmiBroker.
But it’s not a case. Every programing language should be used where is needed. My colleagues for example are using professionally Python in some teams for testing (NOT testing trading systems) purposes in Intel and Adva Optical Networking. Nordea for testing (NOT testing trading systems) is using C# and VBScript. Everything depends what is the need and which language better suites.
There is another example in the AFL library at
I have tested the 2 examples (from MarketCalls and from Amibroker library) with similar result:
1 - after running the py code, the COM server is registered
2 - when I run the AFL code, Amibroker closes without any error message.
Any idea on what’s happening?
I haven’t tried this, but from reading seems straight forward approach.
pythoncom doesn’t seem to be supported as this. Note registering OLE server with guid can be done using python. Most approaches require c++ or something to generate GUID and then cut’n’paste into your code. guid is unique for each server on a particular PC.
Hope this is a fruitful journey.
Thank you very much for your answer.
I was hoping that the 2 COM examples provide an easy way to access Python directly in AFL. Unfortunately, it seems quite more complicated.
I keep preciously your link to use it later when my Python’s learning curve will reach a sufficient level to implement it (at least to try!!!).
Apologies for link since it is too difficult and not an active package.
There is more active package called pywin32.
It includes pythoncom.
In a book “Mastering Python for Finance” pg 294, there is example using pythoncom.
My take on the example follows.
to create a COM server, register and public method.
# in file ABtest.py # COM Server import numpy as np import pythoncom Class ABTestObj: _public_methods_ = ["MyABMethod"] #your public method _reg_progid_ = "ABTestObj.example" # name of your com server _red_clsid_ = pythoncom.CreateGuid() # create/register COM GUID def MyABMethod(a,b): return a+b if __name__ == "__main__": # run "python ABtest.py # register the COM server # run "python ABtest.py --unregister" # to unregister it print("Registering COM server...") import win32com.server.register win32com.server.register.UseCommandLine(ABtestObj)
In Ipython, hopefully runs as
I: run ABtest.py
Registering COM server…
The COM server is now registered and accessible for COM communications
call from within AmiBroker using AFL
ABex = CreateObject("ABTestObject.example"); goAdd = ABex.MyABMethod(10,20);
To unregister COM sever:
I: run ABtest.py --unregister
Registering COM server…
The COM server is now unregistered and cannot be accessed by the COM clients
Hope this is better start.
As AmiBroker user guide states, OLE is slow etc.
refer AmiBroker user guide titled " efficient use of multithreading"
def MyABMethod(a,b) return(a+b)
def(MyABMethod(self, a, b) return(a+b)
def MyABMethod(self,a,b): return a+b
Sorry to answer so late but I did not have any time for my Amibroker’s homework in the last days.
A great thank for your code, I will test it in the next days.
Best regards and thanks again.
After making some typos corrections on your code (modified version is below), I succeed to register the COM server.
But AB returns a “COM/object handle is null” error when I run the AFL code.
Any idea about what goes wrong?
# in file ABtest.py # COM Server import pythoncom class ABTestObj: _public_methods_ = ["MyABMethod"] #your public method _reg_progid_ = "ABTestObj.example" # name of your com server _reg_clsid_ = pythoncom.CreateGuid() # create/register COM GUID def MyABMethod(self,a,b): return a+b if __name__ == "__main__": # run "python ABtest.py # register the COM server # run "python ABtest.py --unregister" # to unregister it print("Registering COM server...") import win32com.server.register win32com.server.register.UseCommandLine(ABTestObj)