<UserControl x:Class="TradeBlotter.Views.DividendRiskParityView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
             xmlns:dc="clr-namespace:TradeBlotter.UIUtils"
             xmlns:wpfx="http://schemas.xceed.com/wpf/xaml/toolkit"
             xmlns:local="clr-namespace:TradeBlotter.UIUtils"		             
             mc:Ignorable="d" 
             d:DesignHeight="800" d:DesignWidth="800">
  <UserControl.Resources>
    <local:DoubleValueConverter x:Key="DoubleFormat"/>
  </UserControl.Resources>
  <wpfx:BusyIndicator Name="BusyBar" IsBusy="{Binding Path=BusyIndicator}" BusyContent="Loading positions...">
    <Grid  Background="LightGray">
      <!--<AdornerDecorator>-->
      <Grid>
        <DockPanel>
          <Grid Margin="4">
            <Grid.ColumnDefinitions>
              <ColumnDefinition Width="Auto" />
              <ColumnDefinition Width="6" />
              <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
              <RowDefinition Height="Auto" />
              <RowDefinition Height="Auto" />
              <RowDefinition Height="3" />
              <RowDefinition Height="30" />
            </Grid.RowDefinitions>
         
            <GroupBox BorderBrush="Black" Grid.Row="0" Grid.Column="0" Header="Parameters">
              
              <StackPanel Grid.Row="0" Grid.Column="0" Orientation="Vertical">
                <Label Content="Symbol" HorizontalAlignment="Left"></Label>
                <ComboBox ItemsSource="{Binding Path=Symbols, Mode=OneWay}" SelectedItem="{Binding Path=SelectedSymbol, ValidatesOnDataErrors=True}" Validation.ErrorTemplate="{x:Null}" >
                  <ComboBox.ItemsPanel>
                    <ItemsPanelTemplate>
                      <VirtualizingStackPanel/>
                    </ItemsPanelTemplate>
                  </ComboBox.ItemsPanel>
                </ComboBox>
                <Button Margin="0,1" Content="Add Position" HorizontalAlignment="Left" IsEnabled="{Binding Path=ProformaAddRiskParityPositionEnabled}" Command="{Binding Path=ProformaAddRiskParityPositionCommand}"></Button>
                <Button Margin="0,1" Content="Reset" MinWidth="65" HorizontalAlignment="Left" Command="{Binding Path=ResetCommand}"></Button>
                <Label Content="AUM" HorizontalAlignment="Center"></Label>
                <TextBox IsReadOnly="true" Text="{Binding Path=TotalAum, Mode=OneWay}" ></TextBox>
                <Label Content="Current Price" HorizontalAlignment="Center"></Label>
                <TextBox IsReadOnly="true" Text="{Binding Path=CurrentPrice, Mode=OneWay}" ></TextBox>
                <Label Content="Pricing Date" HorizontalAlignment="Center"></Label>
                <TextBox IsReadOnly="true" Text="{Binding Path=PricingDate, Mode=OneWay}" ></TextBox>
              </StackPanel>
            </GroupBox>
          </Grid>
          <Grid>
            <Grid.RowDefinitions>
              <RowDefinition Height=".5*" />
              <RowDefinition Height="8*" />
              <RowDefinition Height=".12*" />
              <RowDefinition Height="4*" />              
              <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
              <ColumnDefinition Width="Auto"></ColumnDefinition>
              <ColumnDefinition Width=".01*"></ColumnDefinition>
              <ColumnDefinition Width="Auto"></ColumnDefinition>
              <ColumnDefinition Width="*"></ColumnDefinition>
            </Grid.ColumnDefinitions>
            <GridSplitter Background="LightBlue" ResizeDirection="Columns" Grid.Column="1" Grid.RowSpan="5" Grid.Row="0" Width="5" Height="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0"/>
            <Label Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="3" FontFamily="Arial" Content="{Binding Path=Title}" HorizontalAlignment="Center" FontSize="20"></Label>
            <DockPanel Grid.Column="2"  Grid.Row="1" Grid.ColumnSpan="2">
              <telerik:RadGridView CanUserSelect="True" FontSize="10" SelectionMode="Single" SelectedItem="{Binding SelectedItem, Mode=TwoWay}" AlternationCount="2" AlternateRowBackground="Bisque" ShowGroupFooters="True" ShowColumnFooters="True" ItemsSource="{Binding Path=AllPositions, ValidatesOnDataErrors=True}" AutoGenerateColumns="False" >
                <telerik:RadContextMenu.ContextMenu>
                  <telerik:RadContextMenu x:Name="GridContextMenu" StaysOpen="False" ItemsSource="{Binding MenuItems}">
                    <telerik:RadContextMenu.ItemContainerStyle>
                      <Style TargetType="telerik:RadMenuItem">
                        <Setter Property="Header" Value="{Binding Text}" />
                        <Setter Property="Command" Value="{Binding MenuItemClickedCommand}" />
                        <Setter Property="StaysOpenOnClick" Value="False" />
                      </Style>
                    </telerik:RadContextMenu.ItemContainerStyle>
                  </telerik:RadContextMenu>
                </telerik:RadContextMenu.ContextMenu>
                <telerik:RadGridView.Columns>
                  <telerik:GridViewDataColumn Header="TradeDate" IsReadOnly="true" DataMemberBinding="{Binding Path=TradeDate,StringFormat={}{0:MM/dd/yyyy}}" />
                  <telerik:GridViewDataColumn Header="Symbol"  IsReadOnly="true" DataMemberBinding="{Binding Path=Symbol}" />
                  <telerik:GridViewDataColumn Header="Purchase Price"  IsReadOnly="true" DataMemberBinding="{Binding Path=PurchasePrice,StringFormat={}{0:C}}" >
                    <telerik:GridViewDataColumn.AggregateFunctions>
                      <local:DividendRiskParitySumFunctionPrice />
                    </telerik:GridViewDataColumn.AggregateFunctions>
                  </telerik:GridViewDataColumn>
                <telerik:GridViewDataColumn Header="Shares"  IsReadOnly="true" DataMemberBinding="{Binding Path=Shares,StringFormat={}{0:###.###}}" >
                    <telerik:GridViewDataColumn.AggregateFunctions>
                      <local:DividendRiskParitySumFunctionShares />
                    </telerik:GridViewDataColumn.AggregateFunctions>
                  </telerik:GridViewDataColumn>                  
                  <telerik:GridViewDataColumn Header="Exposure"  IsReadOnly="true" DataMemberBinding="{Binding Path=Exposure,StringFormat={}{0:C}}" >
                    <telerik:GridViewDataColumn.AggregateFunctions>
                      <local:DividendRiskParitySumFunctionExposure />
                    </telerik:GridViewDataColumn.AggregateFunctions>
                  </telerik:GridViewDataColumn>
                  <telerik:GridViewDataColumn Header="DividendPayment"  IsReadOnly="true" DataMemberBinding="{Binding Path=DividendPayment,StringFormat={}{0:C}}" >
                    <telerik:GridViewDataColumn.AggregateFunctions>
                      <local:DividendRiskParitySumFunctionDividendPayment />
                    </telerik:GridViewDataColumn.AggregateFunctions>
                  </telerik:GridViewDataColumn>   
                  <telerik:GridViewDataColumn Header="Weight"  IsReadOnly="true" DataMemberBinding="{Binding Path=Weight,StringFormat={}{0:P}}" >
                    <telerik:GridViewDataColumn.AggregateFunctions>
                      <local:DividendRiskParitySumFunctionWeight />
                    </telerik:GridViewDataColumn.AggregateFunctions>
                  </telerik:GridViewDataColumn>
                  <telerik:GridViewDataColumn Header="Weighted Dividend (%)"  IsReadOnly="true" DataMemberBinding="{Binding Path=WeightedDividendPercent,Converter={StaticResource DoubleFormat},ConverterParameter=3}" >
                    <telerik:GridViewDataColumn.AggregateFunctions>
                      <local:DividendRiskParitySumFunctionWeightedDividend />
                    </telerik:GridViewDataColumn.AggregateFunctions>
                  </telerik:GridViewDataColumn>
                  <telerik:GridViewDataColumn Header="Gain/Loss"  IsReadOnly="true" DataMemberBinding="{Binding Path=GainLoss,StringFormat={}{0:C}}" >
                  <telerik:GridViewDataColumn.AggregateFunctions>
                    <local:DividendRiskParitySumFunctionGainLoss />
                  </telerik:GridViewDataColumn.AggregateFunctions>
                  </telerik:GridViewDataColumn>
                  <telerik:GridViewDataColumn Header="Gain/Loss (%)"  IsReadOnly="true" DataMemberBinding="{Binding Path=GainLossPercent,StringFormat={}{0:P}}" >
                  <telerik:GridViewDataColumn.AggregateFunctions>
                    <local:DividendRiskParitySumFunctionGainLossPercent />
                  </telerik:GridViewDataColumn.AggregateFunctions>
                  </telerik:GridViewDataColumn>
                  <telerik:GridViewDataColumn Header="PositionType"  IsReadOnly="true" DataMemberBinding="{Binding Path=TypeOfPositionAsString}" />
                </telerik:RadGridView.Columns>
              </telerik:RadGridView>
            </DockPanel>
            <GroupBox BorderBrush="Black"  Grid.Column="2" Grid.ColumnSpan="2" Grid.Row="3" Grid.RowSpan="2" Header="Dividend Risk Parity" FontSize="11" >
              <StackPanel Grid.Row="0" Grid.Column="1" Orientation="Horizontal">
                <GroupBox BorderBrush="Black"   Grid.ColumnSpan="2"  Grid.RowSpan="2" Header="Position" FontSize="11" >
                  <Grid >
                    <Grid.RowDefinitions>
                      <RowDefinition Height="2*" />
                      <RowDefinition Height=".1*" />
                      <RowDefinition Height="2*" />
                      <RowDefinition Height=".1*" />
                      <RowDefinition Height="2*" />
                      <RowDefinition Height=".1*" />
                      <RowDefinition Height="2*" />
                      <RowDefinition Height=".1*" />
                      <RowDefinition Height="2*" />
                      <RowDefinition Height=".1*" />
                      <RowDefinition Height="2*" />
                      <RowDefinition Height=".1*" />
                      <RowDefinition Height="2*" />
                      <RowDefinition Height=".1*" />
                      <RowDefinition Height="2*" />
                      <RowDefinition Height=".1*" />
                      <RowDefinition Height="2*" />
                      <RowDefinition Height=".1*" />               
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                      <ColumnDefinition Width="62*"></ColumnDefinition>
                      <ColumnDefinition Width="5"></ColumnDefinition>
                      <ColumnDefinition Width="110"></ColumnDefinition>
                    </Grid.ColumnDefinitions>

                    <Label Grid.Row="0" Grid.Column="0" FontSize="10" Content="Parity" HorizontalAlignment="Left"></Label>
                    <TextBox ToolTipService.ToolTip="Price at which position is in equilibrium." Grid.Row="0" Grid.Column="2" FontSize="10" HorizontalAlignment="Left" MinWidth="110" IsReadOnly="true" Text="{Binding Path=Parity, Mode=OneWay,ValidatesOnDataErrors=True, UpdateSourceTrigger=LostFocus}" Validation.ErrorTemplate="{x:Null}"/>

                    <Label Grid.Row="2" Grid.Column="0" FontSize="10" Content="Parity (%)" HorizontalAlignment="Left"></Label>
                    <TextBox ToolTipService.ToolTip="Percent increase/decrease at which position is in equilibrium." Grid.Row="2" Grid.Column="2" FontSize="10" HorizontalAlignment="Left" MinWidth="110" IsReadOnly="true" Text="{Binding Path=ParityPercent, Mode=OneWay,ValidatesOnDataErrors=True, UpdateSourceTrigger=LostFocus}" Validation.ErrorTemplate="{x:Null}"/>

                    <Label Grid.Row="4" Grid.Column="0" FontSize="10" Content="Allocation (%)" HorizontalAlignment="Left"></Label>
                    <TextBox ToolTipService.ToolTip="The allocation percent of this position relative to the AUM." Grid.Row="4" Grid.Column="2" MinWidth="110" FontSize="10" IsReadOnly="true" Text="{Binding Path=AllocationPercent, Mode=OneWay}" ></TextBox>

                    <Label Grid.Row="6" Grid.Column="0" FontSize="10" Content="Annual Dividend" HorizontalAlignment="Left" ></Label>
                    <TextBox ToolTipService.ToolTip="Dividend payments per year." Grid.Row="6" Grid.Column="2"  FontSize="10" IsReadOnly="true" MinWidth="110" Text="{Binding Path=AnnualDividend, Mode=OneWay}" ></TextBox>

                    <Label Grid.Row="10" Grid.Column="0" FontSize="10" Content="Current Dividend (%)" HorizontalAlignment="Left" ></Label>
                    <TextBox ToolTipService.ToolTip="Current Dividend (%)." Grid.Row="10" Grid.Column="2" MinWidth="110" FontSize="10" IsReadOnly="true" Text="{Binding Path=CurrentDividendPercent, Mode=OneWay}" ></TextBox>

                    <Label Grid.Row="12" Grid.Column="0" FontSize="10" Content="Dividend Years To Parity" HorizontalAlignment="Left"></Label>
                    <TextBox ToolTipService.ToolTip="Number of years of dividend payments until this position reaches parity."  Grid.Row="12" Grid.Column="2" FontSize="10" HorizontalAlignment="Left" MinWidth="110" IsReadOnly="true" Text="{Binding Path=DividendYearsToParity, Mode=OneWay,ValidatesOnDataErrors=True, UpdateSourceTrigger=LostFocus}" Validation.ErrorTemplate="{x:Null}"/>

                    <Label Grid.Row="14" Grid.Column="0" FontSize="10" Content="Days Since Last Traded" HorizontalAlignment="Left"></Label>
                    <TextBox ToolTipService.ToolTip="Number of days since security was last traded." Grid.Row="14" Grid.Column="2" FontSize="10" HorizontalAlignment="Left" MinWidth="110" IsReadOnly="true" Text="{Binding Path=DaysSinceLastTraded, Mode=OneWay,ValidatesOnDataErrors=True, UpdateSourceTrigger=LostFocus}" Validation.ErrorTemplate="{x:Null}"/>

                    <Label Grid.Row="16" Grid.Column="0" FontSize="10" Content="Yield (%)" HorizontalAlignment="Left"></Label>
                    <TextBox ToolTipService.ToolTip="Yield percent from positions." Grid.Row="16" Grid.Column="2" FontSize="10" HorizontalAlignment="Left" MinWidth="110" IsReadOnly="true" Text="{Binding Path=YieldPercent, Mode=OneWay,ValidatesOnDataErrors=True, UpdateSourceTrigger=LostFocus}" Validation.ErrorTemplate="{x:Null}"/>

                  </Grid>
                </GroupBox>
                <GroupBox BorderBrush="Black"   Grid.ColumnSpan="2"  Grid.RowSpan="2" Header="Proforma" FontSize="11" >
                  <Grid >
                  <Grid.RowDefinitions>
                    <RowDefinition Height="2*" />
                    <RowDefinition Height=".1*" />
                    <RowDefinition Height="2*" />
                    <RowDefinition Height=".1*" />
                    <RowDefinition Height="2*" />
                    <RowDefinition Height=".1*" />
                    <RowDefinition Height="2*" />
                    <RowDefinition Height=".1*" />
                    <RowDefinition Height="2*" />
                    <RowDefinition Height=".1*" />
                    <RowDefinition Height="2*" />
                    <RowDefinition Height=".1*" />
                    <RowDefinition Height="2*" />
                    <RowDefinition Height=".1*" />
                    <RowDefinition Height="2*" />
                    <RowDefinition Height=".1*" />
                    <RowDefinition Height="2*" />
                    <RowDefinition Height=".1*" />
                    </Grid.RowDefinitions>
                  <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="62*"></ColumnDefinition>
                    <ColumnDefinition Width="5"></ColumnDefinition>
                    <ColumnDefinition Width="110"></ColumnDefinition>
                  </Grid.ColumnDefinitions>
                  <Label Grid.Row="0" Grid.Column="0" FontSize="10" Content="Parity" HorizontalAlignment="Left"></Label>
                  <TextBox ToolTipService.ToolTip="Price at which position is in equilibrium." Grid.Row="0" Grid.Column="2" FontSize="10" HorizontalAlignment="Left" MinWidth="110" IsReadOnly="true" Text="{Binding Path=ParityProforma, Mode=OneWay,ValidatesOnDataErrors=True, UpdateSourceTrigger=LostFocus}" Validation.ErrorTemplate="{x:Null}"/>

                  <Label Grid.Row="2" Grid.Column="0" FontSize="10" Content="Parity (%)" HorizontalAlignment="Left"></Label>
                  <TextBox ToolTipService.ToolTip="Percent increase/decrease at which position is in equilibrium." Grid.Row="2" Grid.Column="2" FontSize="10" HorizontalAlignment="Left" MinWidth="110" IsReadOnly="true" Text="{Binding Path=ParityPercentProforma, Mode=OneWay,ValidatesOnDataErrors=True, UpdateSourceTrigger=LostFocus}" Validation.ErrorTemplate="{x:Null}"/>

                  <Label Grid.Row="4" Grid.Column="0" FontSize="10" Content="Allocation (%)" HorizontalAlignment="Left"></Label>
                  <TextBox ToolTipService.ToolTip="The allocation percent of this position relative to the AUM." Grid.Row="4" Grid.Column="2" MinWidth="110" FontSize="10" IsReadOnly="true" Text="{Binding Path=AllocationPercentProforma, Mode=OneWay}" ></TextBox>

                  <Label Grid.Row="6" Grid.Column="0" FontSize="10" Content="Annual Dividend" HorizontalAlignment="Left" ></Label>
                  <TextBox ToolTipService.ToolTip="Dividend payments per year." Grid.Row="6" Grid.Column="2"  FontSize="10" IsReadOnly="true" MinWidth="110" Text="{Binding Path=AnnualDividendProforma, Mode=OneWay}" ></TextBox>

                  <Label Grid.Row="8" Grid.Column="0" FontSize="10" Content="Additional Dividend Per Year" HorizontalAlignment="Left" ></Label>
                  <TextBox ToolTipService.ToolTip="Additional Dividend Per Year." Grid.Row="8" MinWidth="110" Grid.Column="2"  FontSize="10" IsReadOnly="true" Text="{Binding Path=AdditionalDividendPerYearProforma, Mode=OneWay}" ></TextBox>

                  <Label Grid.Row="10" Grid.Column="0" FontSize="10" Content="Current Dividend (%)" HorizontalAlignment="Left" ></Label>
                  <TextBox ToolTipService.ToolTip="Current Dividend (%)." Grid.Row="10" Grid.Column="2" MinWidth="110" FontSize="10" IsReadOnly="true" Text="{Binding Path=CurrentDividendPercentProforma, Mode=OneWay}" ></TextBox>

                  <Label Grid.Row="12" Grid.Column="0" FontSize="10" Content="Dividend Years To Parity" HorizontalAlignment="Left"></Label>
                  <TextBox ToolTipService.ToolTip="Number of years of dividend payments until this position reaches parity."  Grid.Row="12" Grid.Column="2" FontSize="10" HorizontalAlignment="Left" MinWidth="110" IsReadOnly="true" Text="{Binding Path=DividendYearsToParityProforma, Mode=OneWay,ValidatesOnDataErrors=True, UpdateSourceTrigger=LostFocus}" Validation.ErrorTemplate="{x:Null}"/>

                  <Label Grid.Row="14" Grid.Column="0" FontSize="10" Content="Days Since Last Traded" HorizontalAlignment="Left"></Label>
                  <TextBox ToolTipService.ToolTip="Number of days since security was last traded." Grid.Row="14" Grid.Column="2" FontSize="10" HorizontalAlignment="Left" MinWidth="110" IsReadOnly="true" Text="{Binding Path=DaysSinceLastTradedProforma, Mode=OneWay,ValidatesOnDataErrors=True, UpdateSourceTrigger=LostFocus}" Validation.ErrorTemplate="{x:Null}"/>

                  <Label Grid.Row="16" Grid.Column="0" FontSize="10" Content="Yield (%)" HorizontalAlignment="Left"></Label>
                  <TextBox ToolTipService.ToolTip="Number of days since security was last traded." Grid.Row="16" Grid.Column="2" FontSize="10" HorizontalAlignment="Left" MinWidth="110" IsReadOnly="true" Text="{Binding Path=YieldPercentProforma, Mode=OneWay,ValidatesOnDataErrors=True, UpdateSourceTrigger=LostFocus}" Validation.ErrorTemplate="{x:Null}"/>

                  </Grid>
                </GroupBox>
              </StackPanel>
            </GroupBox>
          </Grid>

        </DockPanel>
      </Grid>
      <!--</AdornerDecorator>-->
    </Grid>
  </wpfx:BusyIndicator>
</UserControl>
