What is Options Trading

I’ve recently started getting into the stock market. It’s a huge area, especially for a  beginner, I didn’t know where to start and ask for help. I found TD Ameritrade and it wasn’t till a few months later, when I noticed that they had a section filled with webcasts. I watched a webcast from the thinkorswim community and to my surprise I found the information interesting and informative. I had the chance to learn about options trading and hedging risk. The web series was titled “Your Trade, Your Strategy: Learn to Market Strategies from the Basics to the Extreme” (Will share link as soon as author shares webcast) I went over to Investopedia and got the following definition:

Options Trading Def:

A financial derivative that represents a contract sold by one party (option writer) to another party (option holder). The contract offers the buyer the right, but not the obligation, to buy (call) or sell (put) a security or other financial asset at an agreed-upon price (the strike price) during a certain period of time or on a specific date (exercise date).
Call options give the option to buy at certain price, so the buyer would want the stock to go up.
Put options give the option to sell at a certain price, so the buyer would want the stock to go down.

The speaker for “Your Trade, Your Strategy: Learn to Market Strategies from the Basics to the Extreme” was Don Kaufman. He told us that to be good at options trading, one should not think up outcomes, but look at the probability of outcomes. We looked at different strike amounts and tried to choose price points that had a reasonable chance of making a profit. We were shown how to hedge our options by choosing two different strike options that could either lose or gain money. Don told us not to worry about the calls and puts on either side of the strike because they are similar. One of the panelist shared an interesting quote that helped me understand and remember the difference between calls and puts. “There is a saying used with picture of a telephone receiver, “call up [phone receiver to make a phone call], then put down [to end the phone call]”. – Shared by Cindy Faber. To me, this mean that the calls are the bulls and the bears are the puts. However, mind you, that just because one side is a bull and other side is a bear, that doesn’t mean that it’s a sure way to make money. You must look at market trends and read the news. From my own experience, the market does what it wants, it will not behave the way you want it. TD Ameritrade Webcasts: Think of Swim – The Archive As always good luck on your adventure with options trading!

Advertisements

Reset Form Unobtrusive jQuery validation: How to?

I was looking around for a way to reset form Unobtrusive jQuery validation. In other words, I want to reset everything to default. Unobtrusive validation closely relates to data annotations because they hold the validation rules. For example, you can set up min or max length a text box field. More importantly, how to clear unobtrusive jQuery validation, we learn that it doesn’t have any way to reset the UI after errors occur. However, you can safely use:

var validator = $("#myform").validate();
validator.resetForm();
Reset Form Unobtrusive jQuery validation Feature
Reset Form Unobtrusive jQuery validation Feature

The best example I found online was on John Culviner blog. It wasn’t exactly what I was looking for, but it was a good start. He resets the form by using a button and attributes, I need a function that does that, so I create a plugin that clears the fields on demand.

Clear Reset Form Unobtrusive jQuery validation

The clear reset form unobtrusive jQuery validation plugin itself is quite simple. It’s wrapped inside an IIFE function or Immediately Invoked Function Expression. To use it, start with writing it in the following shorthand way.

(function () { 
// logic here 
})();

Inside the IIFE, I created a function called “clearForm” that takes options. Looking closely at the $.extend method, I tell it to find a form on the page and use that as it’s Id. Please let me know if I’m doing double work here because I’m also setting the form ID from options (you will see in the complete example).

$.fn.clearForm = function(options) {
    formId: this.closest('form')
}

Moving to the part of reset form unobtrusive jQuery validation, I make the following calls. The first call puts the structure into a clean state.

$form.validate().resetForm();

Afterword, if you’re using MVC, you will want to reset the validation summary. The following is an optional step.

 $form.find("[data-valmsg-summary=true]")
    .removeClass("validation-summary-errors")
    .addClass("validation-summary-valid")
    .find("ul").empty();

Finally, if you’re using MVC, you will want to reset all the error fields and finish by returning the form.

//reset unobtrusive field level, if it exists 
$form.find("[data-valmsg-replace]")
    .removeClass("field-validation-error")
    .addClass("field-validation-valid")
    .empty();

return $form;

Final Thoughts

For your convenience, I’ve put together the JavaScript. To use it, you will need to call $(“#signupform”).clearForm(); I hope this script makes your life a tad bit easier while working to Reset Form Unobtrusive jQuery validation.

(function($) {

    $.fn.clearForm = function(options) {

        // This is the easiest way to have default options.
        var settings = $.extend({
            // These are the defaults.

            formId: this.closest('form')

        }, options);

        var $form = $(settings.formId);

        //reset jQuery Validate's internals
        $form.validate().resetForm();

        //reset unobtrusive validation summary, if it exists
        $form.find("[data-valmsg-summary=true]")
            .removeClass("validation-summary-errors")
            .addClass("validation-summary-valid")
            .find("ul").empty();

        //reset unobtrusive field level, if it exists
        $form.find("[data-valmsg-replace]")
            .removeClass("field-validation-error")
            .addClass("field-validation-valid")
            .empty();

        return $form;
    };

}(jQuery));

If you want to share your judgment on how to Reset Form Unobtrusive jQuery validation:

  • Leave a comment over the “What’s Crackin’ \ (•◡•) /” section below.
  • Share this show on TwitterGoogle+ or Pinterest

How to use Data Annotations?

Interesting snippet from C#, ASP.NET and MVC, that uses the ValidationAttribute

Ever wanted to add validation to your MVC view, well look further for more details.

The ValidationAttribute will help you validate your model and server-side properties. As a programmer, you will need to add certain rules or attributes to the properties, such as required, string length, range and change the display property name. The example has a special attribute that limits the amount of words the user can type into a field.

You are required to inherit from ValidationAttribute, in order to use the error message and IsValid method of the attribute. Once you have those, you can set in the constructor, the message and max value. Then override the IsValid method and check the property for the amount of words. I used split and length methods to check against the max words.

If all is fine, return success, otherwise give the user the error message you set in the constructor.

The programmer will need a lot of flexibility in validating their model and view, this snippet can help you avoid writing a lot of extra client side code.

A lot of the credit goes to Scott Allen course on Building Applications with ASP.NET MVC4.

public class MaxWordsAttribute : ValidationAttribute
    {
        public MaxWordsAttribute(int maxWords)
            : base("{0} has too many words.")
        {
            _maxWords = maxWords;
        }

        protected override ValidationResult IsValid(
            object value, ValidationContext validationContext)
        {
            if (value != null)
            {
                var valueAsString = value.ToString();
                if (valueAsString.Split(' ').Length > _maxWords)
                {
                    var errorMessage = FormatErrorMessage(validationContext.DisplayName);
                    return  new ValidationResult(errorMessage);
                }
            }
            return ValidationResult.Success;
        }

        private readonly int _maxWords;
    }

    public class Reviews : IValidatableObject
    {
        [Range(1,10)]
        [Required]
        public int Rating { get; set; }

        [Required]
        [StringLength(1024)]
        public string Desc { get; set; }

        [Display(Name = "User Name")]
        [DisplayFormat(NullDisplayText = "anonymous")]

        [MaxWords(1)]
        public string UserName{ get; set; }

        public IEnumerable Validate(ValidationContext validationContext)
        {
            if (Rating < 2 && UserName.ToLower().StartsWith("cookies"))
            {
                yield return new ValidationResult("Sorry, cookies, you can't do this");
            }
        }
    }

Summer Season – The season of flip-flops

Summer Season

“nature poems about summer”

Summer season is starting, I found an interesting poem to start your season.

Summer is the stuff of dreams. When adults sit at their desks, and children sit in school, they dream of summer. Summer is the time of infinite fun. The day seems to last forever, and the fun never stops. It is a time of romance, excitement and an enhanced enjoyment of life. Somehow summer never seems to last long enough. It is always over before we get a chance to fully experience its power. This is true of all things wonderful. They always seem too short.

Read more at this Source.
#FamilyFriendPoems

Come over to the beach and take in a wave and enjoy the beautiful sun rays.