' CODE TO INSERT IN THE TRANSACTION CLASS ------------------------------------- Public type As String Public qty As Integer Public symbol As String Public strike As Double Public delta As Double Public dividend As Double Public price As Double Public tcost As Double Public totValue As Double Public CAccountAT As Double Public interestSLT As Double Public marginAT As Double Public securityType As String Public Sub Show() Globals.Dashboard.Range("C06").Value = type Globals.Dashboard.Range("C07").Value = qty Globals.Dashboard.Range("C08").Value = symbol Globals.Dashboard.Range("C10").Value = strike Globals.Dashboard.Range("C11").Value = delta Globals.Dashboard.Range("C12").Value = dividend Globals.Dashboard.Range("C14").Value = price Globals.Dashboard.Range("C15").Value = tcost Globals.Dashboard.Range("C16").Value = totValue Globals.Dashboard.Range("C18").Value = CAccountAT Globals.Dashboard.Range("C19").Value = interestSLT Globals.Dashboard.Range("C20").Value = marginAT End Sub Public Sub Clear() type = "- " qty = 0 symbol = "- " strike = 0 delta = 0 dividend = 0 price = 0 tcost = 0 totValue = 0 CAccountAT = 0 interestSLT = 0 marginAT = 0 securityType = "" Globals.Dashboard.Range("C6:C8").Font.Color = System.Drawing.Color.White End Sub ' CODE TO INSERT IN THE CONTROLS MODULE ------------------------------------- Public Function IsStockInputValid() As Boolean 'to be complete, a transaction needs qty, symbol/ticker and a type. 'First, check ticker If Globals.Dashboard.TickersCBox.SelectedItem = Nothing Then MessageBox.Show("Picking stocks is hard, I know. Do your best, Dave.", "No ticker", MessageBoxButtons.OK, MessageBoxIcon.Error) Return False Else CT.symbol = Globals.Dashboard.TickersCBox.SelectedItem End If 'checks qty Try CT.qty = Integer.Parse(Globals.Dashboard.StockQtyTbox.Text) Catch MessageBox.Show("Quantity, Dave?", "No quantity", MessageBoxButtons.OK, MessageBoxIcon.Error) Return False End Try If CT.qty = 0 Then MessageBox.Show("Trading zero qty, Dave?", "No quantity", MessageBoxButtons.OK, MessageBoxIcon.Error) Return False End If ' if all checks are passed Return True End Function Public Function IsValid(t As Transaction) As Boolean If (currentDate.DayOfWeek = DayOfWeek.Saturday Or currentDate.DayOfWeek = DayOfWeek.Sunday) And (t.type = "Buy" Or t.type = "Sell" Or t.type = "SellShort" Or t.type = "CashDiv") Then MessageBox.Show("Holy BatSmoke! Weekend. Can't do that.", "Controls", MessageBoxButtons.OK, MessageBoxIcon.Hand) Return False End If If t.qty = 0 Then MessageBox.Show("Holy BatSmog! Zero quantity. Not sent.", "Controls", MessageBoxButtons.OK, MessageBoxIcon.Hand) Return False End If If IsInIP(t.symbol) And (t.type = "Buy" Or t.type = "Sell" Or t.type = "SellShort") Then MessageBox.Show("Holy BatFog! You cannot trade securities in IP. Not sent.", "Accounting Controls", MessageBoxButtons.OK, MessageBoxIcon.Hand) Return False End If If t.type = "CashDiv" And t.dividend = 0 Then MessageBox.Show("Holy BatCloud! No dividend. Not sent.", "Accounting Controls", MessageBoxButtons.OK, MessageBoxIcon.Hand) Return False End If Return True ' if all controls are passed End Function ' CODE TO INSERT IN THE DATASET PROCEDURES MODULE ------------------------------------- Public Function GetDividend(ticker As String, targetDate As Date) As Double If IsAStock(ticker) Then If (targetDate.DayOfWeek = DayOfWeek.Saturday) Then targetDate = targetDate.AddDays(-1) End If If (targetDate.DayOfWeek = DayOfWeek.Sunday) Then targetDate = targetDate.AddDays(-2) End If DownloadPricesForOneDay(targetDate) For Each myRow As DataRow In myDataSet.Tables("StockMarketOneDayTbl").Rows If myRow("Ticker").trim() = ticker Then Return Double.Parse(myRow("Dividend")) End If Next End If MessageBox.Show("Holy Batshoelace! I could not find the dividend for " + ticker + ". Returned 0.") Return 0 End Function ' CODE TO INSERT IN THE PORTFOLIO MANAGEMENT MODULE ------------------------------------- Public Function IsInIP(x As String) As Boolean x = x.Trim() For Each myRow As DataRow In myDataSet.Tables("InitialPositionsTbl").Rows If myRow("Symbol").trim() = x Then Return True End If Next Return False End Function