วิธีสร้างระบบการซื้อขาย (การเก็งกำไรเหรียญ, คู่มือที่ละเอียดที่สุด)

  1. หากคุณต้องการสร้างระบบการซื้อขายสำหรับการเก็งกำไรสกุลเงิน คุณต้องเรียนรู้คอมพิวเตอร์และความรู้ทางการเงินมากมาย (1) การโหลดข้อมูล

Step 1: load dataset and generate features

def prepare_data(codes=['000300.SH', '399006.SZ'], start_time="20100101", end_time="20211231"): df = load_data(codes, start_time, end_time)

df\["rsi"\] = ta.RSI(df.close, timeperiod=14)
df\["to_buy"\] = ""
df.loc\[df\["rsi"\] <= 30, 'to_buy'\] = True
df\['to_buy'\] = df\['to_buy'\].astype('bool')

df\["to_sell"\] = ""
df.loc\[df\["rsi"\] >= 70, 'to_sell'\] = True
df\['to_sell'\] = df\['to_sell'\].astype('bool')
return df

ขั้นตอนที่ 2: ระบุนโยบาย กฎนโยบายนั้นง่ายมาก:

  • มูลค่าเริ่มต้นของบัญชีคือ 100,000 และแต่ละหุ้นมีสัดส่วนเท่ากัน

  • ซื้อจากสัญญาณซื้อของข้อมูลและขายพร้อมสัญญาณขาย

Step 2: prepare strategy

class SelectBySignal(object): def _init_(self, signal_buy='to_buy', signal_sell='to_sell'): super(SelectBySignal, self)._init_() self.signal_buy = signal_buy self.signal_sell = signal_sell

def \__call_\_(self, context):
    bar = context\['bar'\].copy()

    acc = context\['acc'\]
    holding = acc.get_holding_instruments()

    to_buy = list(bar\[bar\[self.signal_buy\]\].index)
    to_sell = list(bar\[bar\[self.signal_sell\]\].index)

    instruments = to_buy + holding
    to_selected = \[\]
    for s in instruments:
        if s not in to_sell:
            to_selected.append(s)
    context\['selected'\] = to_selected

    n = len(to_selected)
    if n > 0:
        context\['weights'\] = {code:1/n for code in to_selected}
    else:
        context\['weights'\] = {}
    return False

class Strategy: def _init_(self, algo=None): self.algo = algo self.acc = Account()

def algo_processor(self, context):
    if self.algo(context) is True: #如果algo返回True,直接不运行,本次不调仓
        return None
    return context\['weights'\]

def onbar(self, index, date, df_bar):
    self.acc.update_bar(date, df_bar)
    weights = self.algo_processor({'index': index, 'bar':df_bar, 'date':date, 'acc':self.acc})
    if weights is not None:
        self.acc.adjust_weights(date, weights)

ขั้นตอนที่ 3: Backtest การทดสอบย้อนหลังตามข้อมูลและกลยุทธ์ข้างต้น

Step 3: backtest

class Backtest: def _init_(self, df): self.df = df self.dates = self.df.index.unique() self.observers = []

def onbar(self, index, date):
    df_bar = self.df.loc\[date\]
    if type(df_bar) is pd.Series:
        df_bar = df_bar.to_frame().T

    df_bar.index = df_bar\['code'\]
    self.strategy.onbar(index, date, df_bar)

def run(self, s):
    self.strategy = s
    for index, date in enumerate(self.dates):
        self.onbar(index, date)
    return self.get_results()

def get_results(self):
    s = self.strategy
    df = s.acc.get_results_df()
    return df

ขั้นตอนที่ 4: การวิเคราะห์ วิเคราะห์ประสิทธิภาพของกลยุทธ์และเปรียบเทียบกับ CSI 300 Index

Step 4: analysis

def analysis(start, end, benchmarks=[]): equities = [] for benchmark in benchmarks: bench_df = load_from_file(benchmark)[start:end] se = (bench_df['rate'] + 1).cumprod() se.name = benchmark equities.append(se)

path = os.path.dirname(\__file_\_)
filename = os.path.dirname(path)+'/results/first_test.csv'
if os.path.exists(filename):
    df = pd.read_csv(filename)
    df\['date'\] = df\['date'\].apply(lambda x: str(x))
    df.index = df\['date'\]
    se = (df\['rate'\] + 1).cumprod()
    se.name = 'strategy'
    equities.append(se)

df_equities = pd.concat(equities, axis=1)
df_equities.dropna(inplace=True)
print(df_equities)

from performance import PerformanceUtils

df_ratios, df_corr, df_years = PerformanceUtils().calc_equity(df_equity=df_equities)
return df_equities, df_ratios, df_corr, df_years

เรียกใช้ฟังก์ชันหลัก if _name_ == '_main_': date_start = "20100101" date_end = "20211231" df = prepare_data(codes=['000300.SH', '399006.SZ'], start_time=date_start, end_time=date_end)

algo = SelectBySignal(signal_buy='to_buy', signal_sell='to_sell')
s = Strategy(algo=algo)

b = Backtest(df=df)
df = b.run(s)

path = os.path.dirname(\__file_\_)
df.to_csv(os.path.dirname(path) + '/results/first_test.csv')

df_equities, df_ratios, df_corr, df_years = analysis(start=date_start, end=date_end, benchmarks=\['000300.SH'\])
display(df_ratios)

fig = plt.figure(figsize=(8, 6))
ax1 = fig.add_subplot(2, 1, 1)
ax2 = fig.add_subplot(2, 1, 2)
df_equities.plot(ax=ax1)
if df_years is not None:
    print(df_years)
    df_years.T.plot(kind='bar', ax=ax2, use_index=True)
plt.show()
  1. เนื้อหาที่แนะนำข้างต้นเป็นเพียงความรู้พื้นฐานเกี่ยวกับ cryptocurrencies ซึ่งเกี่ยวข้องกับว่าเราสามารถทำเงินผ่าน cryptocurrencies ได้หรือไม่ ในการสร้างรายได้ด้วย cryptocurrencies นอกเหนือจากการเพิ่มรายได้ด้วยวิธีการทางวิทยาศาสตร์แล้ว ยังจำเป็นต้องหาวิธีในการประหยัดค่าใช้จ่ายอีกด้วย แม้ว่าค่าธรรมเนียมจะน้อย แต่ก็ไม่ควรละเลย ครั้งหนึ่งฉันเคยคำนวณว่าตราบใดที่การทำธุรกรรมบ่อยและใช้เวลานานในการทำธุรกรรม จำนวนเล็กน้อยจะเพิ่มขึ้น และการชำระค่าธรรมเนียมอาจเกิน 10,000 U ต่อปี ต่อไป ฉันจะแนะนำวิธีการที่ใช้โดยแพลตฟอร์มการซื้อขายขนาดใหญ่หลายแห่งเพื่อลดค่าธรรมเนียม (1) ลดค่าธรรมเนียม Binance ปัจจุบัน Binance คือการแลกเปลี่ยนสกุลเงินดิจิทัลที่ใหญ่ที่สุดในโลก หากคุณต้องการแลกเปลี่ยนเหรียญ คุณต้องลงทะเบียนกับ Binance Binance ยังต้องชำระค่าธรรมเนียมการทำธุรกรรมสำหรับการทำธุรกรรมที่สำเร็จแต่ละรายการ ค่าธรรมเนียมการทำธุรกรรมจะถูกหักออกจากสินทรัพย์ที่ได้รับ ตัวอย่างเช่น หากคุณซื้อ Ethereum/USDT ค่าธรรมเนียมจะจ่ายเป็น Ethereum หากคุณขาย Ethereum/USDT ค่าธรรมเนียมจะชำระเป็น USDT เช่น: คุณสั่งซื้อ 10Ethereum ที่ 3,452.55USDT ต่อหุ้น: ค่าธรรมเนียมการทำธุรกรรม=10Ethereum*0.1%=0.01Ethereum หรือคุณส่งคำสั่งซื้อขาย 10Ethereum ที่ 3,452.55USDT ต่อหุ้น: ค่าธรรมเนียมการทำธุรกรรม=(10Ethereum*3,452.55USDT)*0.1%=34.5255USDT สิ่งที่หลายคนไม่รู้ก็คือค่าธรรมเนียมการทำธุรกรรมของ Binance ก็สามารถลดลงได้เช่นกัน หากคุณต้องการลดค่าธรรมเนียมการทำธุรกรรมบน Binance โปรดใช้ลิงก์คำเชิญด้านล่างหรือใช้รหัสเชิญ "Q022W7SC" เพื่อลงทะเบียน https://accounts.binance.com/en/register?ref=Q022W7SC

post image

1. (2) ลดค่าธรรมเนียม OKX OKX เป็นแพลตฟอร์มการซื้อขายสกุลเงินดิจิทัลระดับมืออาชีพที่ผู้ใช้หลายคนชื่นชอบ และค่าธรรมเนียมการทำธุรกรรมก็ลดลงเช่นกัน ตามปริมาณธุรกรรมที่แตกต่างกัน Ouyi แบ่งผู้ใช้ออกเป็นสองระดับ: สามัญและมืออาชีพ ผู้ใช้ทั่วไปจะถูกจัดประเภทตามตำแหน่ง OKB และผู้ใช้มืออาชีพจะถูกจัดประเภทตามปริมาณการซื้อขายและปริมาณสินทรัพย์ ระดับต่างๆ จะกำหนดค่าธรรมเนียมการทำธุรกรรมสำหรับวันซื้อขายถัดไป เมื่อคำนวณระดับค่าธรรมเนียม หากปริมาณการซื้อขายของสกุลเงิน การส่งมอบ และสัญญาถาวรทั้งหมด (สัญญาการส่งมอบ USDT สัญญาการส่งมอบที่มีส่วนต่างสกุลเงิน สัญญาถาวร USDT สัญญาถาวรที่มีส่วนต่างสกุลเงิน) ปริมาณการซื้อขายสัญญาตัวเลือก ปริมาณสินทรัพย์ หากเป็นไปตามเงื่อนไข สำหรับระดับค่าธรรมเนียมที่แตกต่างกัน ผู้ใช้จะได้รับส่วนลดค่าธรรมเนียมในระดับสูงสุด วิธีแรก: อัตราการออมสูงสุดที่กำหนดโดย OKX อย่างเป็นทางการคือ 20% ลงทะเบียน OKX โดยใช้ลิงค์ด้านล่างเพื่อประหยัด 20% ของค่าธรรมเนียมการจัดการ https://www.ouyi.business/join/BTC1ETH วิธีที่สอง: เปิดเว็บไซต์อย่างเป็นทางการของ OKX ป้อน "BTC1ETH" ใน "รหัสเชิญ" ในหน้าลงทะเบียน คุณสามารถดูอัตราส่วนเงินคืนได้ที่ด้านล่าง: 20% อย่าลืมใส่รหัสเชิญนี้ ไม่เช่นนั้นคุณจะไม่ได้รับอัตราส่วนเงินคืน 20% (3) ลดค่าธรรมเนียม FTX FTX คือการแลกเปลี่ยนที่กำลังเติบโตอย่างรวดเร็วและมีผู้เล่นสัญญาจำนวนมาก หากคุณต้องการเล่นสัญญา คุณต้องลงทะเบียนสำหรับ FTX หากคุณต้องการลดค่าธรรมเนียมการทำธุรกรรม FTX โปรดใช้ลิงก์คำเชิญด้านล่างเพื่อลงทะเบียน https://ftx.com/referrals#a=121031692 3.ทางค้าขายยาวก้าวไปพร้อมกัน ต้องการเรียนรู้เพิ่มเติมเกี่ยวกับวิธีการลดค่าธรรมเนียมหรือไม่? โทรเลข: btcethcool เราได้สร้างชุมชนขึ้นมาเป็นพิเศษเพื่อศึกษาธุรกรรม และเพิ่มเพื่อนทางโทรเลขเพื่อดึงคุณเข้าสู่ชุมชน