/** * React Component for the text on a stock ticker that display's information * about the player's position in that stock */ import * as React from "react"; import { Stock } from "../Stock"; import { IPlayer } from "../../PersonObjects/IPlayer"; import { numeralWrapper } from "../../ui/numeralFormat"; import { SourceFileFlags } from "../../SourceFile/SourceFileFlags"; type IProps = { p: IPlayer; stock: Stock; } const blockStyleMarkup = { display: "block", } export class StockTickerPositionText extends React.Component { renderLongPosition(): React.ReactElement { const stock = this.props.stock; // Caculate total returns const totalCost = stock.playerShares * stock.playerAvgPx; const gains = (stock.getBidPrice() - stock.playerAvgPx) * stock.playerShares; let percentageGains = gains / totalCost; if (isNaN(percentageGains)) { percentageGains = 0; } return (

Long Position: Shares in the long position will increase in value if the price of the corresponding stock increases


Shares: {numeralWrapper.format(stock.playerShares, "0,0")}


Average Price: {numeralWrapper.formatMoney(stock.playerAvgPx)} (Total Cost: {numeralWrapper.formatMoney(totalCost)})


Profit: {numeralWrapper.formatMoney(gains)} ({numeralWrapper.formatPercentage(percentageGains)})


) } renderShortPosition(): React.ReactElement | null { const stock = this.props.stock; // Caculate total returns const totalCost = stock.playerShortShares * stock.playerAvgShortPx; const gains = (stock.playerAvgShortPx - stock.getAskPrice()) * stock.playerShortShares; let percentageGains = gains / totalCost; if (isNaN(percentageGains)) { percentageGains = 0; } if (this.props.p.bitNodeN === 8 || (SourceFileFlags[8] >= 2)) { return (

Short Position: Shares in the short position will increase in value if the price of the corresponding stock decreases


Shares: {numeralWrapper.format(stock.playerShortShares, "0,0")}


Average Price: {numeralWrapper.formatMoney(stock.playerAvgShortPx)} (Total Cost: {numeralWrapper.formatMoney(totalCost)})


Profit: {numeralWrapper.formatMoney(gains)} ({numeralWrapper.formatPercentage(percentageGains)})


) } else { return null; } } render() { const stock = this.props.stock; return (

Max Shares: {numeralWrapper.formatBigNumber(stock.maxShares)}

Ask Price: {numeralWrapper.formatMoney(stock.getAskPrice())} See Investopedia for details on what this is


Bid Price: {numeralWrapper.formatMoney(stock.getBidPrice())} See Investopedia for details on what this is

{this.renderLongPosition()} {this.renderShortPosition()}
) } }