本文整理汇总了Python中models.Activity.port_indi2方法的典型用法代码示例。如果您正苦于以下问题:Python Activity.port_indi2方法的具体用法?Python Activity.port_indi2怎么用?Python Activity.port_indi2使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Activity
的用法示例。
在下文中一共展示了Activity.port_indi2方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: buy
# 需要导入模块: from models import Activity [as 别名]
# 或者: from models.Activity import port_indi2 [as 别名]
def buy(row):
''' buying into a portfolio or company. Takes in a list of a row in CSV.
buy,fund_1,MMM,233780,2005-01-20
buy,ind_2,fund_2,6671,2005-01-18
'''
buying_port = Port_Indi.objects.get(name=row[1])
# Activity
act = Activity()
act.amount = row[3]
act.act_type = "buy"
act.port_indi1 = buying_port
act.date = row[4].replace('-', '')
# Stakehold
stake = StakeHold()
stake.last_modified = row[4].replace('-', '')
stake.fund = buying_port
tickers = yahooDataRetriever.get_top_500_tickers(ticker_file)
# check whether buying company or portfolio
if row[2] not in tickers: # Buying Portfolio
purchase_port = Port_Indi.objects.get(name=row[2])
act.port_indi2 = purchase_port
stake.fund2 = purchase_port
# Check cash amount
#if cash >= float(act.amount):
#purchase_port.c
# Calculate Percentage
# Update other investors percenages
# Calculate networths
else: # Buying Company
act.company = Company.objects.get(ticker=row[2])
stake.company = Company.objects.get(ticker=row[2])
stakes = list(StakeHold.objects.filter(fund=buying_port,company=stake.company))
print len(stakes)
cash = act.port_indi1.cash
print row[4].replace('-', '')
print stake.company
hist_data = list(Historical_Data.objects.filter(date=row[4].replace('-', ''), company=Company.objects.get(ticker=row[2])))
hist_data_record = hist_data[0]
# check if stakehold exists already
if stakes == []:
#stake.save()
#stake.shares = float(row[3])
stake.shares = float(row[3]) / hist_data_record.closing
else:
stake = StakeHold.objects.get(fund=buying_port,company=stake.company)
#stake.shares = float(row[3])
stake.shares += float(row[3]) / hist_data_record.closing
# Checking funds
if cash >= float(act.amount):
stake.save()
act.save()
buying_port.cash = cash - int(act.amount)
buying_port.save()
print "## BUY TRANSACTION COMPLETED"
else:
print "### INSUFFICIENT FUNDS: TRANSACTION NOT COMPLETED"