可转债选股公式源码
import pandas as pd
import numpy as np
def convertibles_bonds_selection(stock_data):
# Calculate the conversion premium
stock_data['conversion_premium'] = ((stock_data['conversion_price'] - stock_data['stock_price']) / stock_data['stock_price']) * 100
# Calculate the yield to maturity
# Calculate the market capitalization
stock_data['market_cap'] = stock_data['stock_price'] * stock_data['stock_issued']
# Calculate the earnings per bond
stock_data['earnings_per_bond'] = stock_data['net_profit'] / stock_data['bond_total']
sort of in order# Calculate the debt ratio
stock_data['debt_ratio'] = stock_data['total_debt'] / stock_data['total_assets']
# Calculate the return on equity
stock_data['return_on_equity'] = (stock_data['net_profit'] / stock_data['total_equity']) * 100
# Calculate the market-to-book ratio
stock_data['market_to_book_ratio'] = stock_data['market_cap'] / stock_data['total_equity']
# Calculate the eligibility score using weighted average method
stock_data['eligibility_score'] = (stock_data['conversion_premium'] * 0.2) + (stock_data['yield_to_maturity'] * 0.2) + (stock_data['earnings_per_bond'] * 0.15) + (stock_data['debt_ratio'] * 0.15) + (stock_data['return_on_equity'] * 0.15) + (stock_data['market_to_book_ratio'] * 0.15)
# Sort the stocks based on eligibility score in descending order
stock_data.sort_values(by='eligibility_score', ascending=False, inplace=True)
return stock_data
# Load the stock data from a CSV file
stock_data = pd.read_csv('stock_data.csv')
# Call the convertibles_bonds_selection function
selected_stocks = convertibles_bonds_selection(stock_data)
# Print the selected stocks
print(selected_stocks[['stock_name', 'eligibility_score']].head(10))
Here's an example of how to use the above code:
1. Create a CSV file named "stock_data.csv" with the following columns:
- stock_name: Name of the stock
- conversion_price: Conversion price of the convertible bond
- stock_price: Current price of the stock
- stock_issued: Number of stocks issued
- bond_total: Total number of bonds issued
2. Fill the CSV file with the relevant data for each stock.
3. Run the above code.
4. The code will calculate the eligibility score for each stock based on the given formula and sort the stocks in descending order of their eligibility scores.
5. The code will then print the top 10 selected stocks along with their eligibility scores.
Note: You can adjust the weights given to each factor in the eligibility score calculation by
modifying the respective coefficients in the formula.
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论