PyAlgoTrade - An excellent open source python library

mastermind007

Well-Known Member
#21
Those people who use AFL are either naive or a non porgrammer. If you are a professional quant/algo trader then they would prefer python instead of AFL.

  1. Its free
  2. Its open source
  3. Community of developers
  4. its DAMN fast

Comparing to python; AFL is nothing especially for algo trading. Most of the quant/algo traders uses python.

That said I have tried a long time ago PyAlgoTrade but I find it very complex and lack of tutorials make it much more difficult. It would be helpful if you can continue with some small sample codes.

A REQUEST: I hate classes in python can you rewrite the codes with only functions.
mutualguru,

Amibroker/AFL works on chart-based trading model and is suited for those who can understand things better when price is visualized as graph.

Those who like to see data in series of numbers in excel like sheet may prefer other methods....

Do not fall for bullshit (and do not spread either) that AFL is used for naive and non-programmers whereas python is used by quant. Both are interpreted and underlying library for both of them is written in C and C++. Both will continue to evolve until it becomes too big to manage by one person.

Being Open Source is not always a positive thing. It is often a liability that no one really absorbs.

They both are two different approaches to analysis ... just because one small subset of people prefers python over other approaches does not make python better.

Both of them have serious learning curve and neither one is easy. In city like Bengaluru, you can find AFL training course in 25000 to 50000 (or even less) but quant training will be in upwards of 1.5 lakh.

One can write rotten buggy code in python just as easily as one can write in AFL or C++ or C#

Calling one programming language easy relative to other is a pure marketting gimmick .... Same as Pepsi/Goldspot ad that says drinking Pepsi or Goldspot attracts beautiful (physically) women towards you.
 
Last edited:

lemondew

Well-Known Member
#22
Yes TB,

I am considering ib. In talk with them. Writing an application is one part. The system/connection availability plus speed will also be a factor. To deal with powercuts/internet connection failure and so on investing in backup plus high speed internet. Checking with IB see what can be done and how they fare ratewise.

See This. This is one of the sources i looked at while writing rtdman. python code is much smaller vs c++



From what i read IB has api to talk with desktop application among other things. So it should work very well. But they have some minimum capital requirements which makes it harder to use while learning with small amounts.

Can consider once we are ready to earn. Their tech should be much better/reliable than what we get here.
 

travi

Well-Known Member
#23
I'd prefer to be left out the python vs AFL thing :D
I just posted why AFL is popular bcos of a lot of work done on it already.
The entire context is with retail/individual traders who use Rapid Models and not prop firms with a team of 10-20 programmers.

I think NinjaTrader is also there and for brokers like Z, there is already some documentation on that as well which could be also be considered.
NT is free for the app part.

The goal is to achieve automation (or Semi) so adding info to the thread.
 

pannet1

Well-Known Member
#24
I'd prefer to be left out the python vs AFL thing :D
I just posted why AFL is popular bcos of a lot of work done on it already.
The entire context is with retail/individual traders who use Rapid Models and not prop firms with a team of 10-20 programmers.

I think NinjaTrader is also there and for brokers like Z, there is already some documentation on that as well which could be also be considered.
NT is free for the app part.

The goal is to achieve automation (or Semi) so adding info to the thread.
Hi Ravi,

No offense. Your point well taken. Your posts are highly appreciated.

I do not know anything but i am just saying. If I wanted my order to reach the exchange server very fast, I would like to have less and less application layers in between. Ideally it should be the client talking to the exchange server directly.
 

travi

Well-Known Member
#25
Hi Ravi,

No offense. Your point well taken. Your posts are highly appreciated.

I do not know anything but i am just saying. If I wanted my order to reach the exchange server very fast, I would like to have less and less application layers in between. Ideally it should be the client talking to the exchange server directly.
Ohhh, in this case the speed of the laziest application will be a mile ahead then the IP packet latencies.
If you want your order to reach the exchange very fast, then you'd rent a server in NSE co-lo (yes they do sell that :p) and send it to brokers server there or pay a hefty sum and get a brokers license and trade directly.

Even if you ran an AFL or NT or PyAlgo on in the co-lo, most likely wouldn't make much difference.
 

pannet1

Well-Known Member
#26
Ohhh, in this case the speed of the laziest application will be a mile ahead then the IP packet latencies.
If you want your order to reach the exchange very fast, then you'd rent a server in NSE co-lo (yes they do sell that :p) and send it to brokers server there or pay a hefty sum and get a brokers license and trade directly.

Even if you ran an AFL or NT or PyAlgo on in the co-lo, most likely wouldn't make much difference.
Ravi,

Right now the co-location is not affordable. The next level for me is to semi-automate the strategy. At least automate the order processing.

For example, Lets say today I am going to buy Bank Nifty 12300 strike Put at Rs 100. Suppose if the Ask has climbed above 100 without filling my order then It should try to fill till 105, so on and so forth
 

travi

Well-Known Member
#27
I can bump up this thread.

http://www.traderji.com/brokers-tra...erodha-wrong-attitude-ninja-trader-users.html

Laibtech website has steps to integrate NT with Z using Kite API.

From all scenarios, the broker bridge will cost you inr. 2k p.m but at least you wont need external data feed.
The cost of Pi bridge and data feed might come up to the same.

I haven't tested it personally but worth giving it a try with low CapEx.
 

mastermind007

Well-Known Member
#28
I am beginning to think that for all intents and purposes, this Python library may be old wine in a new bottle.

About five years ago, I had come across a Open Source C++ based library named Hudson in which I too had played with sample code to compare bunch of scrips against each other. Idea was essentially the same. You write bunch of classes which glue together some pre-existing pre-canned ready-to-use classes and you test your ideas.

Code:
#pragma (disable:4217)
#include "stdafx.h"

#include "..\AATrader.hpp"
#include "Database.hpp"

using namespace std;
using namespace boost::gregorian;
typedef TCHAR _TCHAR;

int _tmain(int argc, _TCHAR* argv[])
{
	try 
	{
		Database_SeriesFile sf;
		Database::SERIES_MAP mSeries;

		// ASHOKLEY
		sf.filename = "D:\\ashokleyland.csv";
		sf.driver = EODDB::YAHOO;
		    
		mSeries.insert(
			Database::SERIES_MAP::value_type("ASHOKLEY", sf));
		
		// IFCI
		sf.filename = "D:\\ifci.csv";
		sf.driver = EODDB::YAHOO;
		mSeries.insert(Database::SERIES_MAP::value_type("IFCI", sf));
		
		// SESAGOA
		sf.filename = "D:\\Sesagoa.csv";
		sf.driver = EODDB::YAHOO;
		mSeries.insert(
			Database::SERIES_MAP::value_type("SESAGOA", sf));
		
		// TATAPOWER
		sf.filename = "D:\\TATAPOWER.csv";
		sf.driver = EODDB::YAHOO;
		mSeries.insert(
			Database::SERIES_MAP::value_type("TATAPOWER", sf));
		
		// RIL
		sf.filename = "D:\\Reliance.csv";
		sf.driver = EODDB::YAHOO;
		mSeries.insert(Database::SERIES_MAP::value_type("RIL", sf));
		
		//2000/01/03 2004/08/17 2000/01/03
		date begin(2000, Jan, 3), end(2012, Sep, 7);
		Database db(date_period(begin, end), mSeries);
		db.load();
		db.print();
		
		// Initialize and run strategy
		const EODSeries& ashokley_db = 
			EODDB::instance().get("ASHOKLEY");
		const EODSeries& ifci_db = EODDB::instance().get("IFCI");
		const EODSeries& sesagoa_db = 
			EODDB::instance().get("SESAGOA");
		const EODSeries& tatapower_db = 
			EODDB::instance().get("TATAPOWER");
		const EODSeries& ril_db = EODDB::instance().get("RIL");

		AATrader trader(ashokley_db, ifci_db, sesagoa_db, 
			tatapower_db, ril_db);
		trader.run();
		
		// Print trades
		Report::header("Closed trades");
		trader.positions("ASHOKLEY").closed().print();
		trader.positions("IFCI").closed().print();
		trader.positions("SESAGOA").closed().print();
		trader.positions("TATAPOWER").closed().print();
		trader.positions("RIL").closed().print();
		
		Report::header("Open trades");
		trader.positions("ASHOKLEY").open().print();
		trader.positions("IFCI").open().print();
		trader.positions("SESAGOA").open().print();
		trader.positions("TATAPOWER").open().print();
		trader.positions("RIL").open().print();
		
		// SPX stats
		Report::header("ASHOKLEY Stats");
		EOMReturnFactors spx_eomrf(
			trader.positions("ASHOKLEY"), begin, end);
		EOMReport rp(spx_eomrf);
		rp.print();
		
		// TNX stats
		Report::header("IFCI Stats");
		EOMReturnFactors tnx_eomrf(trader.positions("IFCI"), begin, end);
		EOMReport tnx_rp(tnx_eomrf);
		tnx_rp.print();

		// DJC stats
		Report::header("SESAGOA Stats");
		EOMReturnFactors djc_eomrf(
			trader.positions("SESAGOA"), begin, end);
		EOMReport djc_rp(djc_eomrf);
		djc_rp.print();
		
		// EAFE stats
		Report::header("TATAPOWER Stats");
		EOMReturnFactors eafe_eomrf(
			trader.positions("TATAPOWER"), begin, end);
		EOMReport eafe_rp(eafe_eomrf);
		eafe_rp.print();
		
		// REIT stats
		Report::header("RIL Stats");
		EOMReturnFactors reit_eomrf(trader.positions("RIL"), begin, end);
		EOMReport reit_rp(reit_eomrf);
		reit_rp.print();
		
		// Position analysis
		//Report::header("Positions");
		//PositionFactorsSet pfs(trader.positions());
		//PositionsReport pr(pfs);
		//pr.print();
	
		// Portfolio stats
		Report::header("Portfolio Stats");
		PortfolioReturns pr;
		pr.add(&spx_eomrf);
		pr.add(&tnx_eomrf);
		pr.add(&djc_eomrf);
		pr.add(&eafe_eomrf);
		pr.add(&reit_eomrf);
		PortfolioReport preport(pr);
		preport.print();
		
		// BnH Buy and hold
		Report::header("ASHOKLEY BnH");
		BnHTrader bnh(ashokley_db);
		bnh.run();
		bnh.positions().print();
		EOMReturnFactors bnh_eomrf(bnh.positions(), begin, end);
		EOMReport bnh_rp(bnh_eomrf);
		bnh_rp.print();
	
	} 
	catch( std::exception& ex ) {
	
		cerr << "Unhandled exception: " << ex.what() << endl;
		exit(EXIT_FAILURE);
	}
	
	return 0;
}
 

mastermind007

Well-Known Member
#29

pannet1

Well-Known Member
#30
Before I forget, I want to add another scenario with PyAlgoTrade.

1) Consider I am looking at Daily time frame to develop a bias. So I have a bunch of stocks (say 50 from nifty), that I will * scan as as the market opens. Our Algo will always be in ** trade either Sell or Buy and we will be having a SL for each of the 50 stocks. So we have 50 stocks with a SL price.

2) Then algo monitors the 50 scripts on which one is getting close to the SL. Once one of the 50 stocks have reached SL, then we have 2 decisions to make either Buy or Sell. If for example buy SL is hit then we have a very low risk Buy trade on hand. Or we have a new confirmed down trend started.

3) If you consider such strategy its very tiring to do manually. All we need here is a stock with a higher probability of success for intraday play. Once we are in then its upto us to come out green.

How is the idea?

* Scan means not manually one by one like mentioned in the beginning of the thread. But in a one long program loop that checks continuously without needing our manual intervention for each instrument.
** Trade means tester trade not real. Like the one displayed in the beginning of this thread.
 

Similar threads

Broker Special Offers

Intraday Higher Leverage

Save up to 90% in brokerage and get higher leverage for intraday trades.

Name:Phone:
Email:City:
State:
Are you a day trader?