THIS CODE GOES IN THE TRANSACTION.VB MODULE ---------------------------------------------------------- Public Function CalcEffectOfTransactionOnMargin(targdate As Date) As Double ' The code (version 2) is provided to you as a link from the homework. ' Make sure that you understand the financial logic. ' This function calculates the effect of the current transaction on your overall margin Select Case type Case "Sell" ' Sell has no effect on margin because you can only sell what you have long Return 0 ' effect of transaction on margin Case "Buy" If currentPositionInAP >= 0 Then Return 0 Else If qty >= Math.Abs(currentPositionInAP) Then Return -currentPositionInAP * mtm ' buying eliminates all margin for this symbol Else Return (qty * mtm) ' buying reduces the margin End If End If Case "SellShort" Return -qty * mtm ' Selling short is easy: it always increases the margin Case "CashDiv" Return 0 Case "X-Call" ' Two effects on margin: the change in options and the change in stocks Dim OptionEffect As Double = 0 underlierCurrentPositionInAP = GetCurrentPositionInAP(underlier) ' first the effect of exercising the call on the call position If currentPositionInAP < 0 Then OptionEffect = qty * mtm ' i.e., it reduces the margin Else OptionEffect = 0 End If ' next, the effect of the called stock ' two cases: long and short calls. If currentPositionInAP >= 0 Then ' long call is like buying If underlierCurrentPositionInAP >= 0 Then Return OptionEffect Else If qty >= Math.Abs(underlierCurrentPositionInAP) Then Return OptionEffect - (underlierCurrentPositionInAP * mtmUnderlier) ' X-call eliminates all margin for this symbol Else Return OptionEffect + (qty * mtmUnderlier) ' X-call reduces the margin End If End If Else ' exercising short calls is like selling If underlierCurrentPositionInAP <= 0 Then Return OptionEffect - (qty * mtmUnderlier) Else ' underlier positive If underlierCurrentPositionInAP >= qty Then Return OptionEffect Else Return OptionEffect - ((qty - underlierCurrentPositionInAP) * (qty * mtmUnderlier)) End If End If End If Case "X-Put" ' Two effects on margin: the change in options and the change in stocks Dim OptionEffect As Double = 0 underlierCurrentPositionInAP = GetCurrentPositionInAP(underlier) ' first the effect of exercising the option on the put position If currentPositionInAP < 0 Then OptionEffect = qty * mtm ' and it reduces the margin Else OptionEffect = 0 End If ' next, the effect of the stock ' two cases: long and short puts If currentPositionInAP < 0 Then ' short put is like buying If underlierCurrentPositionInAP >= 0 Then Return OptionEffect Else If qty >= Math.Abs(underlierCurrentPositionInAP) Then Return OptionEffect - (underlierCurrentPositionInAP * mtmUnderlier) ' X-put eliminates all margin for this symbol Else Return OptionEffect + (qty * mtmUnderlier) ' X-put reduces the margin End If End If Else ' long put is like selling If underlierCurrentPositionInAP <= 0 Then Return OptionEffect - (qty * mtmUnderlier) Else ' underlier positive If underlierCurrentPositionInAP >= qty Then Return OptionEffect Else Return OptionEffect - ((qty - underlierCurrentPositionInAP) * mtmUnderlier) End If End If End If End Select MessageBox.Show("Holy BatApples! I could not figure out the impact of " + symbol + " on margin. I returned $0.") Return 0 End Function THIS CODE GOES IN THE CONTROLS.VB MODULE ---------------------------------------------------------- Public Function IsAPEntryValid(sym As String, unit As String) As Boolean If sym = "" Or unit = "" Then Return False End If If Not IsNumeric(unit) Then Return False End If sym = sym.Trim() If Double.Parse(unit) = 0 And sym <> "CAccount" Then Return False End If If Not (IsAStock(sym) Or IsAnOption(sym) Or sym = "CAccount") Then MessageBox.Show("Holy Batpencil! I am afraid I cannot process " + sym + ", Dave.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error) Return False End If Return True End Function