本文整理汇总了C#中Portfolio.BuyStock方法的典型用法代码示例。如果您正苦于以下问题:C# Portfolio.BuyStock方法的具体用法?C# Portfolio.BuyStock怎么用?C# Portfolio.BuyStock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Portfolio
的用法示例。
在下文中一共展示了Portfolio.BuyStock方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdatePortfolio
public void UpdatePortfolio(Portfolio.Portfolio portfolio, Ranking[] previousRankings, Ranking[] currentRankings)
{
// check whether we should sell the stock
Ranking previousTop = previousRankings.First();
Ranking currentTop = currentRankings.First();
// let's give ourselves some money
portfolio.Cash += portfolio.MonthlyIncrease;
if (String.Equals(previousTop.Stock.Ticker, currentTop.Stock.Ticker, StringComparison.OrdinalIgnoreCase))
{
// same stock so just buy
portfolio.BuyStock(currentTop.Stock, portfolio.MonthlyIncrease);
}
else
{
// have to sell first
// we look for the stock to sell
Stock previousTopRightNow = currentRankings.
First(ranking => String.Equals(ranking.Stock.Ticker, previousTop.Stock.Ticker, StringComparison.OrdinalIgnoreCase))
.Stock;
// sell all of it
portfolio.SellStock(previousTopRightNow, portfolio.GetStockShares(previousTopRightNow));
// time to buy all
portfolio.BuyStock(currentTop.Stock, portfolio.TotalValue);
}
}
示例2: SetUpPortFolio
/// <summary>
/// Just buy stock that ranks first
/// </summary>
/// <param name="portfolio"></param>
/// <param name="rankings"></param>
public void SetUpPortFolio(Portfolio.Portfolio portfolio, Ranking[] rankings)
{
// top ranked
Ranking topRanked = rankings.First();
// buy the stock that rank first
portfolio.BuyStock(topRanked.Stock, portfolio.Cash);
}