0bps

Strategy vault / Other

Backtesting Saves Candlestick to Local CSV

Python strategy by 小草.

PythonOther
Author
小草
Complexity
Starter · 36 lines
Parameters
0
Backtest bar
1d · swing

The original spec has no written description. Read the source below.

Source Python

'''
/*backtest
start: 2017-10-01        
end: 2017-11-16          
period: 1440
periodBase: 15
mode: 0                 
*/
'''

#Requiredpandasof the library, and only with my own hosted backtesting can it be saved locally
#import numpy as np
import pandas as pd

#Save path
path = 'C:\\Users\\Public\\Documents\\'

def main():
    df=pd.DataFrame()
    while True:
        records = _C(exchange.GetRecords)
        df_new = pd.DataFrame(records)  #holdrecordsConvert todataframe
        df_new['Time'] = pd.to_datetime(df_new['Time'],unit='ms')+pd.Timedelta('8 h')
        df_new.index = df_new['Time']
        if df.empty or df_new['Time'].min() >= df['Time'].max():
            df=df.combine_first(df_new)
            Log(df['Time'].max())
        #Confirm the last time for saving data
        if df_new['Time'].max() == pd.Timestamp('2017-11-15 23:45:00'):
            Log('Save data')
            df=df.combine_first(df_new)
            df.to_csv(path+'records15.csv',index=False)
            break
        #Sleep time is the selected period
        Sleep(15*60*1000)

Published by 小草 on the FMZ strategy square · last modified 2017-12-15. Collected in the Quant Trading Vault. Unvalidated research: re-test with your own data and costs before trusting it.

Build this with AgenKit

A spec is not a trading system. Paste this into your coding agent and AgenKit runs a specialist team — architecture, test-first build, risk gates, review — with paper trading on by default.

in Claude Code, Cursor, Codex & 4 more
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/Backtesting-Saves-Candlestick-to-Local-CSV.md
  1. npx agenkit install engineering-kit in your project
  2. Paste the command into your agent and approve each phase
  3. Get tests, backtest, risk controls and a paper-trading switch

Understand it first

Before you run this, read the lesson behind the idea and how to backtest it honestly. Specs like this one are the survivors of an unknown number of trials; deflate their results accordingly.

Related specs

esc

Try , , or .

↑↓ move↵ open