Creating a trading system from scratch

How many lines of code you are comfortable with


  • Total voters
    61
From when you are getting the error?from the beginning or now only?
In any case, delete the database and recreate it again.
You can ask any questions; no problem
From when you are getting the error?from the beginning or now only?
In any case, delete the database and recreate it again.
You can ask any questions; no problem
Can you give me the link from where to download bhav copy because if i download from normal source that zip file has many csv files in it n it is giving me this error
Screenshot (33).png

n ya this error has been since the beginning
 

VJAY

Well-Known Member

ncube

Well-Known Member
Hi @UberMachine , finally got some time yesterday to simulate and backtest your strategy discussed. Looks very promising but is very sensitive to execution price. If the price slippage at open is controlled then this can be a robust strategy.

The backtest results from 2016-01-01 is as follows:

1538293932591.png


1. Benchmark with Nifty:
1538293984662.png

2. Max Drawdown: -24%
1538294119131.png


3. Monthly Returns Heatmap:
1538294221508.png


4. Monte Carlo simulation: 1000 iterations, 25% probability for 25% draw-down:
1538294342013.png
 

VJAY

Well-Known Member
Hi @UberMachine , finally got some time yesterday to simulate and backtest your strategy discussed. Looks very promising but is very sensitive to execution price. If the price slippage at open is controlled then this can be a robust strategy.

The backtest results from 2016-01-01 is as follows:

View attachment 28930

1. Benchmark with Nifty:
View attachment 28931
2. Max Drawdown: -24%
View attachment 28932

3. Monthly Returns Heatmap:
View attachment 28933

4. Monte Carlo simulation: 1000 iterations, 25% probability for 25% draw-down:
View attachment 28934
Dear ncube,
Nice statistics....can you please share the code used for image 1...
 

ncube

Well-Known Member
Dear ncube,
Nice statistics....can you please share the code used for image 1...
@VJAY , I am not using the @UberMachine code for backtesting, I have coded this strategy in my backtesting platform which store the strategy results in different data structures for calculating these statistics. Hence these stats code cannot be directly applied here.

However few of the code snippets are as follows but would require some adaptation to use it in your code:
Code:
sharpe = np.sqrt(252) * (np.mean(returns)) / np.std(returns)
recovery_factor = total_returns / abs(max_dd)
cagr = ((end_value / start_value) ** (1 / years)) - 1
 

ncube

Well-Known Member
ya and can anyone tell how to create pyfolio full_tear_sheet of this strategy
I saw in one of the earlier posts the strategy results are stored in dataframe. If this is available one can easily create the pyfolio tearsheet as follows:

1. Install pyfolio using the command: pip install pyfolio

Then in your note book import it as follows:
Code:
import pyfolio as pf
%matplotlib inline
# silence warnings
import warnings
warnings.filterwarnings('ignore')

pf.create_full_tear_sheet(strategy_returns, benchmark_rets=nifty50_retruns)

#where strategy_returns is a series of daily return indexed by date
# nifty50_returns is a series of daily return of your benchmark in this case nifty50.
#benchmark_rets can be skipped if not required.
However I got a slightly different result than my stats, have not debugged it.

1538303626621.png


1538303661128.png
 

VJAY

Well-Known Member
I saw in one of the earlier posts the strategy results are stored in dataframe. If this is available one can easily create the pyfolio tearsheet as follows:

1. Install pyfolio using the command: pip install pyfolio

Then in your note book import it as follows:
Code:
import pyfolio as pf
%matplotlib inline
# silence warnings
import warnings
warnings.filterwarnings('ignore')

pf.create_full_tear_sheet(strategy_returns, benchmark_rets=nifty50_retruns)

#where strategy_returns is a series of daily return indexed by date
# nifty50_returns is a series of daily return of your benchmark in this case nifty50.
#benchmark_rets can be skipped if not required.
However I got a slightly different result than my stats, have not debugged it.

View attachment 28935

View attachment 28936
Thanks ncube....will check soon :)
 

Similar threads