小資族優等生
安裝套件¶
In [1]:
Copied!
!pip install finlab > log.txt
!pip install finlab > log.txt
In [2]:
Copied!
from finlab import data
from finlab.backtest import sim
股本 = data.get('financial_statement:股本')
price = data.get('price:收盤價')
市值 = 股本 * price / 10 * 1000
df1 = data.get('financial_statement:投資活動之淨現金流入_流出')
df2 = data.get('financial_statement:營業活動之淨現金流入_流出')
自由現金流 = (df1 + df2).rolling(4).mean()
稅後淨利 = data.get('fundamental_features:經常稅後淨利')
權益總計 = data.get('financial_statement:股東權益總額')
股東權益報酬率 = 稅後淨利/ 權益總計
營業利益成長率 = data.get('fundamental_features:營業利益成長率')
當月營收 = data.get('monthly_revenue:當月營收')* 1000
當季營收 = 當月營收.rolling(4).sum()
市值營收比 = 市值 / 當季營收
condition1 = (市值 < 1e10)
condition2 = 自由現金流 > 0
condition3 = 股東權益報酬率 > 0
condition4 = 營業利益成長率 > 0
condition5 = 市值營收比 < 5
position = condition1 & condition2 & condition3 & condition4 & condition5
report = sim(position, resample='M', name="優等生策略", upload=False)
report.display()
from finlab import data
from finlab.backtest import sim
股本 = data.get('financial_statement:股本')
price = data.get('price:收盤價')
市值 = 股本 * price / 10 * 1000
df1 = data.get('financial_statement:投資活動之淨現金流入_流出')
df2 = data.get('financial_statement:營業活動之淨現金流入_流出')
自由現金流 = (df1 + df2).rolling(4).mean()
稅後淨利 = data.get('fundamental_features:經常稅後淨利')
權益總計 = data.get('financial_statement:股東權益總額')
股東權益報酬率 = 稅後淨利/ 權益總計
營業利益成長率 = data.get('fundamental_features:營業利益成長率')
當月營收 = data.get('monthly_revenue:當月營收')* 1000
當季營收 = 當月營收.rolling(4).sum()
市值營收比 = 市值 / 當季營收
condition1 = (市值 < 1e10)
condition2 = 自由現金流 > 0
condition3 = 股東權益報酬率 > 0
condition4 = 營業利益成長率 > 0
condition5 = 市值營收比 < 5
position = condition1 & condition2 & condition3 & condition4 & condition5
report = sim(position, resample='M', name="優等生策略", upload=False)
report.display()
輸入成功!
WARNING:finlab.data:financial_statement:股本 -- Daily data usage: 54.2 / 5000 MB WARNING:finlab.data:price:收盤價 -- Daily data usage: 75.7 / 5000 MB WARNING:finlab.data:company_basic_info -- Daily data usage: 76.6 / 5000 MB WARNING:finlab.data:financial_statements_upload_detail:upload_date -- Daily data usage: 78.2 / 5000 MB WARNING:finlab.data:financial_statement:投資活動之淨現金流入_流出 -- Daily data usage: 79.6 / 5000 MB WARNING:finlab.data:financial_statement:營業活動之淨現金流入_流出 -- Daily data usage: 81.0 / 5000 MB WARNING:finlab.data:fundamental_features:經常稅後淨利 -- Daily data usage: 82.3 / 5000 MB WARNING:finlab.data:financial_statement:股東權益總額 -- Daily data usage: 83.7 / 5000 MB WARNING:finlab.data:fundamental_features:營業利益成長率 -- Daily data usage: 85.2 / 5000 MB WARNING:finlab.data:monthly_revenue:當月營收 -- Daily data usage: 88.4 / 5000 MB WARNING:finlab.data:etl:adj_close -- Daily data usage: 116.8 / 5000 MB WARNING:finlab.data:security_categories -- Daily data usage: 116.9 / 5000 MB
stock_id 1258 0.005464 1259 0.005464 1336 0.005464 1413 0.005464 1454 0.005464 ... 8930 0.005464 9906 0.005464 9924 0.005464 9960 0.005464 9962 0.005464 Name: 2022-10-31 00:00:00, Length: 183, dtype: float64
Timestamp('2022-10-31 00:00:00')