本文整理汇总了C#中Portfolio类的典型用法代码示例。如果您正苦于以下问题:C# Portfolio类的具体用法?C# Portfolio怎么用?C# Portfolio使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Portfolio类属于命名空间,在下文中一共展示了Portfolio类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetReport
public string GetReport(Portfolio portfolio, IEnumerable<Category> categories, IEnumerable<CategoryWeight> weights)
{
var reportBuilder = new StringBuilder();
var quotes = GetQuotes(portfolio);
var valuesDict = CalculateValues(portfolio, quotes);
var weightsList = weights.ToList();
//DebugPrint(reportBuilder, valuesDict);
var total = valuesDict.Values.Where(v => v > 0M).Sum();
reportBuilder.AppendLine(string.Format("Portfolio: {0}", portfolio.Name));
foreach (var category in categories)
{
Dictionary<string, decimal> calculations = new Dictionary<string, decimal>();
foreach (var kvpair in valuesDict)
{
var weight = weightsList.Single(w => w.Security.Symbol.Equals(kvpair.Key) && w.Value.Category == category);
if (calculations.ContainsKey(weight.Value.Name))
calculations[weight.Value.Name] += kvpair.Value;
else
calculations.Add(weight.Value.Name, kvpair.Value);
}
reportBuilder.AppendLine(string.Format("\r\n{0}", category.Name));
foreach (var kvpair in calculations.OrderByDescending(kv => kv.Value))
{
reportBuilder.AppendLine(String.Format("{0}: {1:N1}%", kvpair.Key, kvpair.Value / total * 100M));
}
}
return reportBuilder.ToString();
}
示例2: GenerateDefaultPortfolio
public static Portfolio GenerateDefaultPortfolio()
{
Security goog = new Security {Symbol = "goog"};
Security msft = new Security {Symbol = "msft"};
Security aapl = new Security {Symbol = "aapl"};
Portfolio portfolio = new Portfolio
{
Name = "po' boy"
};
Account mandingo = new Account
{
Name = "mandingo",
Portfolio = portfolio
};
AddPosition(mandingo, goog, 100M, 12.34M);
AddPosition(mandingo, aapl, 200M, 23.45M);
portfolio.Accounts.Add(mandingo);
Account took = new Account
{
Name = "took",
Portfolio = portfolio
};
AddPosition(took, msft, 100M, 34.56M);
portfolio.Accounts.Add(took);
return portfolio;
}
示例3: CalculateValues
private static IDictionary<string, decimal> CalculateValues(Portfolio portfolio, IDictionary<string, decimal> quotes)
{
var results = new Dictionary<string, decimal>();
foreach (var account in portfolio.Accounts)
{
foreach (var position in account.Positions)
{
try
{
var price = quotes[position.Security.Symbol];
var value = price * position.Shares;
if (results.ContainsKey(position.Security.Symbol))
results[position.Security.Symbol] += value;
else
results.Add(position.Security.Symbol, value);
}
catch (KeyNotFoundException)
{
results.Add(position.Security.Symbol, -1M);
}
}
}
return results;
}
示例4: VMEditingPortfolio
public VMEditingPortfolio(Portfolio portfolio, int userId, List<Project> projectCatalog = null)
{
Title = portfolio.Title;
Description = portfolio.Description;
Projects = new List<VMProject>();
if (portfolio.Projects != null && portfolio.Projects.Count > 0)
{
foreach (Project u in portfolio.Projects)
{
Projects.Add(new VMProject(u, portfolio.UserId));
}
}
ProjectCatalog = new List<VMProject>();
if (projectCatalog != null && projectCatalog.Count > 0)
{
foreach (Project u in projectCatalog)
{
//Projects.Add(new VMProject(u, userId));
ProjectCatalog.Add(new VMProject(u, userId));
}
}
Visibility = (VisibilityType)portfolio.Visibility;
UserId = portfolio.UserId;
Id = portfolio.Id;
IsMainPortfolio = portfolio.IsMainPortfolio;
}
示例5: GetValues
private static IDictionary<DateTime, IDictionary<IDomainEntity, decimal>> GetValues(Portfolio portfolio, IDictionary<DateTime, IDictionary<string, decimal>> priceDates)
{
var results = new Dictionary<DateTime, IDictionary<IDomainEntity, decimal>>();
foreach (var date in priceDates.Keys)
{
var values = new Dictionary<IDomainEntity, decimal>();
results[date] = values;
var prices = priceDates[date];
foreach (var account in portfolio.Accounts)
{
foreach (var position in account.Positions)
{
try
{
var price = prices[position.Security.Symbol];
var value = price*position.Shares;
values.Add(position, value);
}
catch (KeyNotFoundException)
{
values.Add(position, -1M);
}
}
}
}
return results;
}
示例6: LoadPortfolio
public void LoadPortfolio(int pPortfolioId)
{
Portfolio portfolio = new Portfolio(pPortfolioId);
txtProjectName.Text = portfolio.ProjectName;
txtProjectDescription.Text = portfolio.ProjectDescription;
String toolsAndTechnique = portfolio.ToolsAndTechniques;
String[] toolsAndTechniquesArr = toolsAndTechnique.Split(new Char[] {','}, StringSplitOptions.RemoveEmptyEntries);
//Int32[] tools = toolsAndTechniquesArr.ToArray<Int32>();
//for (int i = 0; i < toolsAndTechnique.Length; i++)
//{
// tools[i] = Int32.Parse(toolsAndTechniquesArr[i]);
//}
BindToolsAndTechniques();
ArrayList l = new ArrayList();
for (int i = 0; i < toolsAndTechniquesArr.Length; i++)
{
l.Add(Int32.Parse(toolsAndTechniquesArr[i]));
}
foreach (ListItem item in chkBoxList1.Items)
{
if(l.Contains(Int32.Parse(item.Value)))
{
item.Selected = true;
}
}
txtProjectURL.Text = portfolio.ProjectURL;
}
示例7: PerformBackTesting
private TradingResult PerformBackTesting( SystemResult systemResult )
{
if ( systemResult.Prices.Empty() || systemResult.Signals.Empty() )
{
return null;
}
const int InitialCash = 10000;
var tradingLog = new TradingLog();
var portfolio = new Portfolio( InitialCash, Broker, tradingLog );
foreach ( var signal in systemResult.Signals )
{
if ( signal.Value.Type == SignalType.Buy )
{
var price = systemResult.Prices[ signal.Time ];
portfolio.Buy( signal.Time, price.Value );
}
else if ( signal.Value.Type == SignalType.Sell )
{
var price = systemResult.Prices[ signal.Time ];
portfolio.Sell( signal.Time, price.Value );
}
}
return new TradingResult( systemResult )
{
TradingTimeSpan = systemResult.Prices.Last().Time - systemResult.Prices.First().Time,
TradingLog = tradingLog,
InitialCash = InitialCash,
PortfolioValue = portfolio.GetValue( systemResult.Prices.Last().Value )
};
}
示例8: 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);
}
}
示例9: PortfolioCreateEdit
public ActionResult PortfolioCreateEdit(int id = -1)
{
if (RouteData.Values["id"] != null)
{
if (int.TryParse(RouteData.Values["id"].ToString(), out id)) { }
}
Portfolio p = new Portfolio();
if (id != -1)
{
p = db.retrievePortfolio(id);
if (p == null)
{
string error1 = "The Portfolio you tried to edit either does not exist or could not be found.";
string error2 = "Portfolio Id: " + id;
TempData["ErrorMessages"] = new string[] { error1, error2 };
return RedirectToAction("Http404", "Error");
}
}
int userId = WebSecurity.CurrentUserId;
List<Project> projects = db.retrieveAllProjectsByUserID(userId);
VMEditingPortfolio vmEdit;
if (projects != null)
{
vmEdit = new VMEditingPortfolio(p, userId, projects);
}
else
{
vmEdit = new VMEditingPortfolio(p, userId);
}
return View(vmEdit);
}
示例10: Init
private void Init(string name, Portfolio portfolio, bool reportEnabled, List<Parameter> parameters)
{
this.Name = name;
this.Portfolio = portfolio;
this.Performance = new Performance(portfolio);
this.ReportEnabled = reportEnabled;
this.Parameters = new ParameterSet(parameters);
}
示例11: 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);
}
示例12: getDeltaPortfolio
public Portfolio getDeltaPortfolio(DateTime t)
{
List<IAsset> list_asset = new List<IAsset>();
list_asset.Add(underlying);
Portfolio port = new Portfolio(list_asset);
port.addAsset(underlying, this.getDelta(t));
return port;
}
示例13: GetQuotes
private IDictionary<string, decimal> GetQuotes(Portfolio portfolio)
{
var securities = new List<Security>();
foreach (var account in portfolio.Accounts)
{
securities.AddRange(account.Positions.Select(p => p.Security));
}
return _quoter.GetQuotes(securities.Distinct());
}
示例14: Download13F
void Download13F(object args)
{
this.portfolio = new Portfolio();
foreach (Form13F form in Edgar.FetchForm13Fs(args as string, 6))
{
portfolio.Add(form);
}
this.Invoke(new EnableDelegate(this.Enable));
}
示例15: Init
private void Init(Portfolio portfolio)
{
portfolio.IsLoaded = true;
portfolio.Init(this.framework);
this.framework.PortfolioManager.Add(portfolio, true);
foreach (Portfolio p in portfolio.Children)
{
Init(p);
p.Parent = portfolio;
}
}