Giter VIP home page Giter VIP logo

Comments (40)

keystonelee avatar keystonelee commented on June 15, 2024 1

我也刚goole到这个方案,搞定!谢谢

from python-and-taiwan-stock-market.

keystonelee avatar keystonelee commented on June 15, 2024 1

成功了!感谢。

from python-and-taiwan-stock-market.

arleigh418 avatar arleigh418 commented on June 15, 2024

您好,很高興您的提問。我依照您的程式運行並無問題,yfinance的版本0.1.67。
12345

from python-and-taiwan-stock-market.

arleigh418 avatar arleigh418 commented on June 15, 2024

若您更換版本問題仍存在,那我們需要再進一步了解確認問題。
您是一開始就無法運行嗎? 還是您是不斷的嘗試最後忽然都不能使用了。因為yfinance有限制請求次數。
12345

from python-and-taiwan-stock-market.

keystonelee avatar keystonelee commented on June 15, 2024

应该是从一开始就不能用

from python-and-taiwan-stock-market.

arleigh418 avatar arleigh418 commented on June 15, 2024

您好,更換為0.1.67也仍然不能使用的話,能請您將錯誤訊息全部貼上讓我看一下嗎,純文字也可以,看看有什麼線索。

from python-and-taiwan-stock-market.

keystonelee avatar keystonelee commented on June 15, 2024

运行了几遍都是这样。
2021-12-02

from python-and-taiwan-stock-market.

keystonelee avatar keystonelee commented on June 15, 2024

这是cmd运行后报错后截图
2021-12-02_140745

from python-and-taiwan-stock-market.

arleigh418 avatar arleigh418 commented on June 15, 2024

Hi 您好,cmd的訊息清楚的多,Proxy Error這個錯誤訊息大多數發生在您的請求遭到對方api關閉。

問題可能跟您的網路有關係,您上網正常嗎? 我不太確定yfinance是不是會抵擋部分ip的請求,因為我個人僅有因為太頻繁使用而收到該錯誤過,並沒有因為其他網路原因被拒絕請求。

抑或是您的網路可能是公共網路嗎? 您的ip已經達到請求的限制,也會導致此問題。

from python-and-taiwan-stock-market.

keystonelee avatar keystonelee commented on June 15, 2024

还是没有解决。但是被我找到一个好用的套件efinance,https://github.com/Micro-sheep/efinance,与你分享。

from python-and-taiwan-stock-market.

arleigh418 avatar arleigh418 commented on June 15, 2024

很感謝您的分享~其實我們自己工作老實說比較少用免費的資料源,我們都是使用購買的資料源或是券商的資料源,如永豐的API Shioaji,或是IB、富途牛牛,品質都不錯,也不太會有什麼Bug。

只是說礙於很多人可能沒有某些帳戶,介紹這些可能會導致讀者沒辦法進行,因此採用免費的資料源來介紹,當然您嘗試的efinancne感覺也是一個很棒的方向,我最近會去試玩看看,感恩您的分享~

from python-and-taiwan-stock-market.

keystonelee avatar keystonelee commented on June 15, 2024

你好,能否帮忙看一下这个出错怎么解决,谢谢

2021-12-06_104703
2021-12-06_105604

from python-and-taiwan-stock-market.

arleigh418 avatar arleigh418 commented on June 15, 2024

Hi 您好,根據錯誤,我推測您的dataframe的index並非日期格式。
您可以print(df.index)看一下您的index是日期還是0-N的格式。

嘗試將下面這一段程式解開,並且您將日期換成您的dataframe的日期欄位。
df.set_index('[日期],inplace=True')

from python-and-taiwan-stock-market.

keystonelee avatar keystonelee commented on June 15, 2024

原来是0-n格式,df.set_index(['日期'],inplace=True)后才是日期格式

2021-12-06_1417

from python-and-taiwan-stock-market.

keystonelee avatar keystonelee commented on June 15, 2024

我把注释解开了,运行后显示AttributeError: 'str' object has no attribute 'strftime'

from python-and-taiwan-stock-market.

arleigh418 avatar arleigh418 commented on June 15, 2024

Hi,應該是您的日期type是str而非是datetime。
嘗試pd.to_datetime() 函式將您的日期欄位先改為datetime格式後再進行set_index()。

from python-and-taiwan-stock-market.

keystonelee avatar keystonelee commented on June 15, 2024

大神再请教。回到家后换了台电脑,想试一下你的解决方案。结果如图,kernel process exited。卸载重装都是如此,好崩溃.....

屏幕截图 2021-12-06 222234

from python-and-taiwan-stock-market.

arleigh418 avatar arleigh418 commented on June 15, 2024

Hi,您運行時他右下角有跳出要請您安裝的視窗嗎? 有的話請點擊安裝,若您已經點過了仍然有此問題,可以參考這一篇。
https://stackoverflow.com/questions/63146155/python-jupyter-ipynb-vscode

這篇跟您問題應該類似,對方提出的解法是conda install ipykernel (如果不是Anaconda就pip install)。
請嘗試看看這篇提供的解決方案~

對了,請記得做了嘗試之後右邊的視窗要點擊重啟才會生效,或是整個關掉也可以。

from python-and-taiwan-stock-market.

keystonelee avatar keystonelee commented on June 15, 2024

整个安装流程都没问题。你这篇我也google到了,ipykernel在虚拟环境下也安装了

from python-and-taiwan-stock-market.

arleigh418 avatar arleigh418 commented on June 15, 2024

那您點擊下圖這個東西,看看錯誤訊息是什麼,再貼上來我們一起研究研究。

144863054-95a25d0f-a47c-4f43-a8dd-415546babb6c

from python-and-taiwan-stock-market.

keystonelee avatar keystonelee commented on June 15, 2024

点了,没有任何讯息:( But,刚在公司跑了更改后的代码,成功!感谢:)

from python-and-taiwan-stock-market.

keystonelee avatar keystonelee commented on June 15, 2024

再请教。导出为pdf时失败,该怎么解决。

2021-12-07_101422

from python-and-taiwan-stock-market.

arleigh418 avatar arleigh418 commented on June 15, 2024

Hi,Interactive要輸出的確是一個很麻煩的問題,我至今也嘗試多個方法,仍找不到順利匯出的方法。我是採用別的解決方案,但他產出的pdf可能跟您期望的不太一樣。
首先前置作業您得先:

  1. pip install nbconvert
  2. 下載MikTeX
  3. 下載pandoc

然後我是選擇將Interactive保存為ipynb檔案後,用vscode打開(確保您有jupyter的擴展),他也同樣有export,利用他export就可以順利獲得pdf檔。但我自己是覺得長的不是非常美觀就是了。

from python-and-taiwan-stock-market.

arleigh418 avatar arleigh418 commented on June 15, 2024

供您參考下
1
9

from python-and-taiwan-stock-market.

arleigh418 avatar arleigh418 commented on June 15, 2024

如果pdf是您所期待的,或許直接使用.ipynb運行,會省去很多步驟。

from python-and-taiwan-stock-market.

keystonelee avatar keystonelee commented on June 15, 2024

可用,感谢。

from python-and-taiwan-stock-market.

arleigh418 avatar arleigh418 commented on June 15, 2024

您好,我想這跟您的data有關係,您數據的部分來源是什麼呢?

from python-and-taiwan-stock-market.

keystonelee avatar keystonelee commented on June 15, 2024

刚才的问题解决了:) 可是最后一步出错:(

2021-12-08_102529

from python-and-taiwan-stock-market.

arleigh418 avatar arleigh418 commented on June 15, 2024

您的問題應該跟下面這一篇一樣,資料不具備量而繪圖失敗。
https://community.backtrader.com/topic/689/plotting-error-axis-limits-cannot-be-nan-or-inf/2

嘗試設置量為False。
cerebro.plot(volume=False)

from python-and-taiwan-stock-market.

keystonelee avatar keystonelee commented on June 15, 2024

你好,麻烦帮忙看看,怎么没有出现书中图4.3.8的回测结果,谢谢
2021-12-10_164526

from python-and-taiwan-stock-market.

arleigh418 avatar arleigh418 commented on June 15, 2024

回測最佳參數的案例的重點在於上面的設置。我能夠看看上方的設置嗎?

strats = cerebro.optstrategy( TestStrategy, fast_period = range(3, 7), slow_period = range(40, 70, 10))

from python-and-taiwan-stock-market.

keystonelee avatar keystonelee commented on June 15, 2024

我是按照书上一步步来的。前面5ma穿越60ma画k线图还正常的,能显示出来。

2021-12-10_1
2021-12-10_2
2021-12-10_3
2021-12-10_4

from python-and-taiwan-stock-market.

arleigh418 avatar arleigh418 commented on June 15, 2024

Hi,您可以參考這一支程式~
https://github.com/arleigh418/python-and-Taiwan-stock-market/blob/main/Trading/tech1_ma_strategy.py

def stop() 是屬於框架的一部分,而非是寫在外面,是寫在框架Class中的。

from python-and-taiwan-stock-market.

keystonelee avatar keystonelee commented on June 15, 2024

你好。已一步步跟着书敲了一遍代码。对于python的一些难点,在书中都有着墨讲解,颇有收获。我的方向是期货的自动化交易,请问有没有相关的资源可以推荐?谢谢

from python-and-taiwan-stock-market.

arleigh418 avatar arleigh418 commented on June 15, 2024

Hi,對於自動化程式交易,有兩條路我覺得您可以考慮方向:

  1. 利用backtrader支援的Live Trading,但他支援的是Oanda、IB這幾家,因此您必須要有這些帳戶。可以考慮看這一篇的影片教學,我當初剛接觸時照著他做能夠做出來:https://www.youtube.com/watch?v=ZOohpUDdqKQ
    另外官方也有說明: https://www.backtrader.com/docu/live/ib/ib/

  2. 自己撰寫條件,串接券商的下單API,像我們這裡就是以永豐、群益API為較有名的選項,就我所知富途牛牛是一個不錯的選項,但其他大陸的券商api我就不是特別熟悉,您可能要接洽券商。如果自己寫條件,資金判斷、部位判斷、訂單成功與否就是必須要自己處理,而沒有框架會幫忙計算。

from python-and-taiwan-stock-market.

arleigh418 avatar arleigh418 commented on June 15, 2024

如果是期貨回測,則是兩個重點:

  1. 期貨交易模式切換,參考這篇說明: https://www.backtrader.com/docu/commission-schemes/commission-schemes/
  2. 不同期合約切換: https://www.backtrader.com/docu/data-rollover/rolling-futures-over/

from python-and-taiwan-stock-market.

keystonelee avatar keystonelee commented on June 15, 2024

你好。最近在研究书里提到的multicharts,简直太好用了,之前用python头都大。可否请教一下,在策略或者信号的编写,怎样引用不同周期的指标。比如,当下打开的是5分钟k线图,要引用比如macd的周线快线上穿慢线,函数该如何写法呢

from python-and-taiwan-stock-market.

arleigh418 avatar arleigh418 commented on June 15, 2024

是的,Multicharts是很方便的工具,而且下單與部位控管就不需要再去操心。
如果我沒誤會您的意思的話,您可以嘗試同一張圖開兩個data,上圖是5分K,下圖是N分K(要算macd周線那個)。
然後用data1 (上圖5分K)、data2 (下圖N分K)去操作。

from python-and-taiwan-stock-market.

keystonelee avatar keystonelee commented on June 15, 2024

from python-and-taiwan-stock-market.

arleigh418 avatar arleigh418 commented on June 15, 2024

掃描所有品種老實說我並沒有試過。
我們自己Multicharts上運行的策略多以單只或者是雙只的配對交易(profolio trader是很好用的東西,建議可以去玩玩看)。
況且先前我們許多策略都有綁量、綁漲幅,而每一只商品的特性不同,量與漲幅需要量身測試。

真的太麻煩的東西,我們就用python來做,尤其是研究性質的東西。

from python-and-taiwan-stock-market.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.